LinearLayout :线性布局
属性 | 可选值 | 说明 |
---|---|---|
orientation | vertical:垂直排列 horizontal:水平排列 | 也就是这个线性布局到底是水平方向逐个排列还是垂直方向逐个排列 |
layout_width layout_height | 1.match_parent:填充父容器的剩余空间 2.wrap_content:根据内容宽高自适应自己的宽高 3.自定义大小 | layout_width和layout_height是android中的必要属性,规定了控件的宽度和高度 |
background | 填充背景色(对于button按钮要用backgroudTint) | |
gravity | 1.center:所有子内容相对于父容器居中显示 2.horizontal_center:所有内容的横向方向上相对父容器居中显示 3.vertical_center:所有内容的纵向方向上相对父容器居中显示 | 决定子控件相对该父容器的位置 |
layout_gravity | 1.center:该容器相对于它的父容器居中显示 2.horizontal_center:该容器横向方向上相对它的父容器居中显示 3.vertical_center:该容器纵向方向上相对它的父容器居中显示 | 决定该容器相对它的父容器的位置 |
weight | 按比例分配父容器剩余的宽度或高度 |
orientation
注:按钮改变颜色要用backgroudTint
水平方向排列
竖直方向排列
weight
layout_gravity
注:layout_gravity和orientation一般要搭配使用
RelativeLayout:相对布局
相对于父元素 7个常用属性
属性 | 可选值 | 说明 |
---|---|---|
layout_alignParentTop | true/false | 是否让控件相对于父容器顶部对齐 |
layout_alignParentBottom | true/false | 是否让控件相对于父容器底部对齐 |
layout_alignParentLeft | true/false | 是否让控件相对于父容器左边对齐 |
layout_alignParentRight | true/false | 是否让控件相对于父容器右边对齐 |
layout_centerHorizontal | true/false | 相对父容器水平居中显示 |
layout_centerVertical | true/false | 相对父容器垂直居中显示 |
centerInParent | true/false | 相对父容器居中显示 |
相对于兄弟元素 4个常用属性
属性 | 可选值 | 说明 |
---|---|---|
layout_above | @+id/ | 指定在那个控件的上侧 |
layout_below | @+id/ | 指定在那个控件的上侧 |
android:layout_toLeftOf | @+id/ | 指定在那个控件的左侧 |
android:layout_toRightOf | @+id/ | 指定在那个控件的右侧 |
相对于兄弟元素的对齐方式
属性 | 可选值 | 说明 |
---|---|---|
layout_alignLeft | @+id/ | 该控件的左边沿与指定控件的左边对齐 |
layout_aliginRight | @+id/ | 该控件的右边沿与指定控件的右边对齐 |
layout_alignTop | @+id/ | 该控件的上边沿与指定控件的上边沿对齐 |
layout_alignBottom | @+id/ | 该控件的下边沿与指定控件的下边沿对齐 |
FrameLayout
常用属性
属性 | 可选值 | 说明 |
---|---|---|
layout_gravity | center/center_vertical/center_horizontal | 组件相对父容器的位置 |
layout_marginLeft | 具体的数值100dp | 左侧外间距 |
layout_marginTop | 具体的数值100dp | 上侧外间距 |
layout_marginRight | 具体的数值100dp | 右侧外间距 |
layout_marginBottom | 具体的数值100dp | 下侧外间距 |
ConstraintLayout:约束布局
相对位置
属性 | 可选值 |
---|---|
layout_constraintLeft_toRightOf | @+id/或parent |
layout_constraintRight_toLeftOf | @+id/或parent |
layout_constraintRight_toRightOf | @+id/或parent |
layout_constraintTop_toTopOf | @+id/或parent |
layout_constraintTop_toBottomOf | @+id/或parent |
layout_constraintBottom_toTopOf | @+id/或parent |
layout_constraintBottom_toBottomOf | @+id/或parent |
layout_constraintBaseline_toBaselineOf | @+id/或parent |
layout_constraintStart_toEndOf | @+id/或parent |
layout_constraintStart_toStartOf | @+id/或parent |
layout_constraintEnd_toStartOf | @+id/或parent |
layout_constraintEnd_toEndOf | @+id/或parent |
参考文献