大家好 I am HYJones
相信大家在学习Android开发的时候是不是想过也想做出高大尚的页面 那你算是来对地方啦
下面将传授大家的秘籍就是 Android 页面布局实现固定顶部和底部导航栏
大家有没有发现我们平常使用的软件都是固定顶部和底部的菜单栏的 ,而中间的部分是可以上下滑动的。这样软件的界面就会比较使用 而且有b格 。
如果你也想实现这样的效果,看啦这篇文章 你也可以轻松实现,全是基础知识,只用线性布局即可实现 。
先看一下效果,体验一下快感。
页面颜色多是为啦看的更明白
直接上源码
activity_main.xml
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#F1E60909"
android:orientation="horizontal"
tools:ignore="MissingConstraints">
<Button
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent">
Button>
<Button
android:background="@color/white"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent">
Button>
<Button
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent">
Button>
<Button
android:background="@color/white"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent">
Button>
LinearLayout>
<ScrollView android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
tools:ignore="MissingConstraints">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:ignore="MissingConstraints">
<LinearLayout android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/purple_200">
LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/teal_200">
LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/teal_700">
LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/white">
LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/purple_500">
LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/purple_200">
LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/black">
LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/purple_200">
LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/white">
LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/purple_500">
LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/teal_200">
LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/purple_200">
LinearLayout>
LinearLayout>
ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#F1E60909"
tools:ignore="MissingConstraints">
<Button
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent">
Button>
<Button
android:background="@color/white"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent">
Button>
<Button
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent">
Button>
<Button
android:background="@color/white"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent">
Button>
LinearLayout>
LinearLayout>
androidx.constraintlayout.widget.ConstraintLayout>
<ScrollView> ScrollView> // 页面滑动标签
用法
<ScrollView android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
tools:ignore="MissingConstraints">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:ignore="MissingConstraints">
可滑动内容
LinearLayout>
ScrollView>
```
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)