2 布局

  1. LinearLayout(线性布局)
  2. RelativeLayout(相对布局)
  3. TableLayout(表格布局)
  4. FrameLayout(帧布局)
  5. AbsoluteLayout(绝对布局)
  6. GridLayout(网格布局)

2.2.1 LinearLayout(线性布局)

常用属性
orientation: 布局中组件的排列方式,horizontal水平,vertical垂直(默认)
gravity: 控制组件所含子元素的对齐方式,可组合
layout_gravity: 控制组件在父容器中对齐方式
layout_width: 布局宽度,wrap_content组件实际大小,match_parent填满父容器
layout_height: 布局高度
id: 为组件设置资源id
background: 为组件设置背景图片

Weight(权重)
该属性用于等比例划分区域

divider分割线
该属性用于为LinearLayout设置分割线,通过showDividers设置分割线位置,可选值none,middle,beginning,end;dividerPadding设置分割线padding

2.2.2 RelativeLayout(相对布局)

基本属性
gravity: 设置容器内组件对齐方式
ignoreGravity: 该属性为true组件不受gravity属性影响

根据父容器定位
layout_alignParentLeft 左对齐
layout_alignParentRight 右对齐
layout_alignParentTop 顶部对齐
layout_alignParentBottom 底部对齐
android:layout_centerHorizontal 水平居中
android:layout_centerVertical 垂直居中
android:layout_centerInParent 中间位置

根据兄弟组件定位
layout_toLeftOf 参考组件左边
layout_toRightOf 参考组件右边
layout_above 参考组件上方
layout_below 参考组件下方
layout_alignTop 对齐参考组件上边界
layout_alignBottom 对齐参考组件下边界
layout_alignLeft 对齐参考组件左边界
layout_alignRight 对齐参考组件右边界

偏移
layout_margin
layout_marginTop
layout_marginBottom
layout_marginLeft
layout_marginRight

填充
padding
paddingTop
paddingBottom
paddingLeft
paddingRight

你可能感兴趣的:(2 布局)