UI学习
UI分类
安卓的UI分为两大类:一类叫做View视图,一类叫做ViewGroup容器
- View视图:TextView,Button,ImageView都是常见的视图
- ViewGroup容器:内部尅承载、放置、添加View视图的容器
布局方式
安卓布局主要有:线性布局、相对布局、帧布局、约束布局
LinearLayout线性布局
LinearLayout线性布局:横着或者竖着 按顺序排列
其属性主要有:
- orientation:排列方向,主要有
vertical垂直排列、horizontal水平排列 - layout_width/height:宽度,主要有三种类型
- 填充父容器剩余空间:match_parent
- 根据子视图宽度自适应自己的宽高:wrap_content
- 自定义大小,比如50dp
- background:背景颜色
- gravity:重力,决定子控件相对该父容器的位置。主要有三种:
center:居中显示
horizontal_center:水平居中
vertical_center:垂直居中 - layout_gravity:决定该容器相对它的父容器的位置
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FF2299"
android:gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#FF00FF"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#FFFF00"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#00FF00"/>
</LinearLayout>

RelativeLayout相对布局
在摆放子视图位置时,按照指定的参考系摆放子视图的位置,默认以屏幕左上角(0, 0)位置作为参考系摆放位置
主要有三大类:
- 相对父元素
- 相对兄弟元素
- 相对兄弟元素对齐方式


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:insetTop="0dp"
android:insetBottom="0dp"
android:text="按钮1"/>
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height=

本文详细介绍了AndroidUI设计中的View和ViewGroup概念,以及LinearLayout、RelativeLayout、FrameLayout和MaterialButton的使用方法,同时展示了RecyclerView和自定义列表的实现。
最低0.47元/天 解锁文章
845

被折叠的 条评论
为什么被折叠?



