LinearLayout 线性布局
orientation //布局中组件的排列方式
gravity 控制组件所包含的子元素的对齐方式,可多个组合
layout_gravity 控制该组件在父容器里的对其方式
background 为该组件设置一个背景图片,或者是直接用颜色覆盖
divider 分割线(可用view代替 高1dp)
showDividers 设置分割线所在的位置,none(无),beginning(开始),end(结束),middle(每两个组件间)
7.dividerPadding 设置分割线的 padding
8.layout_weight (权重)该属性是用来等比例的划分剩余区域
设置为线性布局将layout设置如下:
<LinearLayout //布局方式为线性布局
xmlns:android="http://schemas.android.com/apk/res/android" //匹配命令是否正确
android:layout_width="match_parent" //宽
android:layout_height="match_parent" //高
android:orientation="horizontal" // 设置线性方向vertical为垂直hor...为水平
</LinearLayout>
android:layout_weight="0" //控件中设置权重,设置屏幕占比,该控件占自己权重/总权重数
RelativeLayout 相对布局
对于整个页面内(默认左上角)
android:layout_centerHrizontal //在水平居中
android:layout_centerInparent //相对于父元素完全居中
android:layout_centerVertical //垂直居中
android:layout_alignParentBottom //位于父元素的下边缘
android:layout_alignParentLeft //位于父元素的左边缘
android:layout_alignParentRight //位于父元素的右边缘
android:layout_alignParentTop //位于父元素的上边缘
对于控件
android:layout_above //位于控件的的上方
android:layout_below //位于控件的下方
android:layout_toRightOf //位于元素的右边
android:layout_toLeftOf //位于元素的左边
android:layout_alignTop //该控件和某控件的上边缘对齐
android:layout_alignBottom //该控件和某控件的下边缘对齐
android:layout_alignLeft //该控件和某控件的左边缘对齐
android:layout_alignRight // 该控件和某控件的右边缘对齐
距离页面边距
android:layout_marginBottom 底边缘的距离
android:layout_marginLeft 左边缘的距离
android:layout_marginRight 右边缘的距离
android:layout_marginTop 上边缘的距离
padding 父容器内的边距
<RelativeLayout //相对布局
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
AbsoluteLayout 绝对布局
Android:layout_x //x坐标
Android:layout_y //y坐标
<AbsoluteLayout //决对布局
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
TableLayout 表格布局
默认占用一行
android:collapseColumns //设置需要被隐藏的列的序号,从0开始设置
android:stretchColumns //允许被拉伸的列的列序号,从0开始
android:shrinkcolumns //设置允许被收缩的列的列序号,从0开始
子控件设置属性
android:layout_column //显示在第几列
android:layout_span //横向跨几列
<TableRow> </TableRow>
<TableLayout //表格布局
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
GridLayout (比表格布局更灵活)
android:orientation //设置水平显示还是垂直显示
android:columnCount //设置行的显示个数
android:rowCount // 设置列的显示个数
子控件属性
android:layout_column //显示在第几列
android:layout columnSpan //横向跨几列
android:layout_columnWeight // 横向剩余空间分配方式
android:layout_gravity //在网格中的显示位置
android:layout_row //显示在第几行
android:layout rowSpan //横向跨几行
android:layout_rowWeight // 纵向剩余空间分配方式
FrameLayout 帧布局
<FrameLayout
默认左上角
foreground 设置前景
foregroundGravity 设置前景位置
ConstraintLayout 约束布局
主要拖动然后自动生成
从左到右分别是 页边距 取消所有约束 生成约束 约束线