常用布局
共有属性:
- android:layout_width 宽度
- android:layout_height 高度
- android:layout_padding 内边距
- android:layout_margin 外边距
1、LinearLayout线性布局
- android:layout_orientation 方向
- horizontal 水平(默认)
- vertical 垂直
- android:layout_weight 权重
- 根据父类的屏幕尺寸划分
- 如果指定该元素,一般要把android:layout_width=”0dp”,以免影响布局效果
- android:layout_gravity 重力
- right、left只对horizontal有效(因为水平,上下无空间,所以。。)
- top、bottom只对vertical有效
2、Relativelayout相对布局
-
相对于父容器(取值:true/false)
- android:layout_centerInParent
- android:layout_ alignParentLeft
- android:layout_alignParentRight
- android:layout_alignParentTop
- android:layout_alignparentBottom
- android:layout centerHorizontal
- android:layout_centerVertical
-
相对于其他控件(取值:其他控件id)
1.在参照物的某边
- android:layout_toLeftOf
- android:layout_toRightOf
- android:layout above
- android:layout below
2.和参照物的某达线对齐
- android:layout_alignTop
- android:layout_alignBottom
- android:layout_alignLeft
- android:layout_alignRight
3、FrameLayout帧布局
- android:layout_gravity(控件重力)
- android:gravity (相对于控件内容的位置布局)
- android:foreground(前景图片)
- android:foregroundGravity(前景重力)
4、 TableLayout表格布局
-
android:stretchColumns 设置可伸展的列(多列用,分割,所有用*)
-
android:shrinkColumns 设置可收缩的列
-
android:collapseColumns 设置可隐藏的列
如果直接在TableLayout中添加控件,那么控件将和父容器等宽 如果想让控件出现在同一行,那么这些控件的外层一定要加一对<TableRow> 在TableRow中的控件,宽度都是默认wrap_content
5、GridLayout网格布局
-
android:rowCount(行数量)
-
android:columnCount(列数量)
-
android:layout_row(位于第几行)
要使用下面的属性,必须搭配android:layout_gravity=fill,才有效果
-
android:layout_rowSpan(跨几行)
-
android:layout_columnSpan(跨几列)
6、ConstraintLayout约束布局
- app:layout_constraintVertical_bias 水平偏移量,取值0~1 ,默认0.5
- app:layout_constraintRight_toLeftOf=“id”
-
app:layout_contraint本源_to目标="目标id"