一、LinearLayout(线性布局)
常用属性
- orientation: 布局中组件的排列方式
- gravity: 控制组件所包含的子元素的对齐方式
- layout_gravity: 控制该组件在父容器里的对齐方式
- background: 设置背景,可以是颜色
- divider: 分割线
- showDivider: 设置分割线位置,none(无),beginning(开始),end结束),middle(每两个组件之间)
- dividerPadding: 设置分割线的padding
- layout_weight: 权重,按比例划分空间
二、RelativeLayout(相对布局)
常用属性
根据父容器定位
- layout_alignParentLeft: 与父容器左对齐
- layout_alignParentRight: 与父容器右对齐
- layout_alignParentTop: 与父容器顶部对齐
- layout_alignParentBottom: 与父容器底部对齐
- layout_centerHorizontal: 水平居中与父容器
- layout_centerVertical: 垂直居中于父容器
- layout_centerParent: 居中于父容器
根据兄弟组件定位
- layout_toLeftOf: 放置于参考组件左侧
- layout_tuRightOf: 放置于参考组件右侧
- layout_above: 放置于参考组件上方
- layout_below: 放置于参考组件下方
- layout_alignTop: 对齐参考组件上边界
- layout_alignBottom: 对齐参考组件下边界
- layout_alignLeft: 对齐参考组件左边界
- layout_alignRight: 对齐参考组件右边界
- layout_alignBaseline: 该控件的baseline(基线)和指定控件的baseline对齐
三、FrameLayout(帧布局)
常用属性
- foreground: 设置前景
- foregroundGravity: 设置前景位置
四、TableLayout(表格布局)
一般和TableRow结合使用
常用属性
- collapseColumns: 设置需要被隐藏的列的序号,从0开始
- stretchColumns: 设置允许被拉伸的列的序号,从0开始
- shrinkColumns: 设置允许被收缩的列的序号,从0开始
子控件设置属性
- layout_column: 显示在第几列
- layout_ span: 横向跨几列
五、GridLayout(网格布局)
常用属性
- android:columnCount: 最大列数
- android:rowCount: 最大行数
- android:orientation: 布局方向
子控件设置属性
- layout_column: 组件显示在第几列
- layout_columnSpan: 横向跨几列
- layout_columnWeight: 组件垂直方向权重
- layout_gravity: 组件的对齐方式
- layout_row: 组件显示在第几行
- layout_rowSpan: 横向跨几行
- layout_rowWeight: 组件向权重
通过layout_rowSpan和layout_columnSpan设置跨越的列数和行数后,通过layout_gravity=”fill”即可将该组件填满所跨越的整行或整列
通过网格布局设置响应式工具栏
通过对GridLayouy的columnCount和rowCount设置,达到响应式工具栏
1.当手机屏幕时,设置columnCount为4,此时显示两行四列
2.当平板电脑屏幕时,设置columnCount为6,此时显示一行六列
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| <?xml version="1.0" encoding="utf-8"?> <GridLayout android:background="#12fa21" android:columnCount="4" android:rowCount="2" android:id="@+id/grid" android:layout_width="match_parent" android:layout_height="200dp"> <LinearLayout android:layout_columnWeight="1" android:gravity="center" android:layout_rowWeight="1"> <ImageView android:src="@mipmap/ic_launcher" android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout> <LinearLayout android:layout_columnWeight="1" android:gravity="center" android:layout_rowWeight="1"> <ImageView android:src="@mipmap/ic_launcher" android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout> <LinearLayout android:layout_columnWeight="1" android:gravity="center" android:layout_rowWeight="1"> <ImageView android:src="@mipmap/ic_launcher" android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout> <LinearLayout android:layout_columnWeight="1" android:gravity="center" android:layout_rowWeight="1"> <ImageView android:src="@mipmap/ic_launcher" android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout> <LinearLayout android:layout_columnWeight="1" android:gravity="center" android:layout_rowWeight="1"> <ImageView android:src="@mipmap/ic_launcher" android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout> <LinearLayout android:layout_columnWeight="1" android:gravity="center" android:layout_rowWeight="1"> <ImageView android:src="@mipmap/ic_launcher" android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout> <LinearLayout android:layout_columnWeight="1" android:gravity="center" android:layout_rowWeight="1"> <ImageView android:src="@mipmap/ic_launcher" android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout> <LinearLayout android:layout_columnWeight="1" android:gravity="center" android:layout_rowWeight="1"> <ImageView android:src="@mipmap/ic_launcher" android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout> </GridLayout>
|
六、ConstraintLayout(约束布局)
学尼玛,不学了