相对布局
相对布局(RelativeLayout)是一种很是灵活的布局方式,可以经过指定界面元素与其余元素的相对位置关系,肯定界面中全部元素的布局位置。相对布局和线性布局有着共同的优势,可以最大程度保证在各类屏幕类型的手机正确的显示界面布局。android
相对布局的各类属性
相对于兄弟元素布局
- android:layout_below="@id/aaa":在指定View的下方
- android:layout_above="@id/xxx":在指定View的上方
- android:layout_toLeftOf="@id/bbb":在指定View的左边
- android:layout_toRightOf="@id/cccc":在指定View的右边
相对于父元素spa
- android:layout_alignParentLeft="true":在父元素内左边
- android:layout_alignParentRight="true":在父元素内右边
- android:layout_alignParentTop="true":在父元素内顶部
- android:layout_alignParentBottom="true":在父元素内底部
对齐方式3d
- android:layout_centerInParent="true":居中布局
- android:layout_centerVertical="true":水平居中布局
- android:layout_centerHorizontal="true":垂直居中布局
- android:layout_alignTop="@id/xxx":与指定View的上边界一致
- android:layout_alignBottom="@id/xxx":与指定View下边界一致
- android:layout_alignLeft="@id/xxx":与指定View的左边界一致
- android:layout_alignRight="@id/xxx":与指定View的右边界一致
间隔code
- android:layout_marginBottom=""; 离某元素底边缘的距离
- android:layout_marginLeft=""; 离某元素左边缘的距离
- android:layout_marginRight ="";离某元素右边缘的距离
- android:layout_marginTop=""; 离某元素上边缘的距离
- android:layout_paddingBottom=""; 离父元素底边缘的距离
- android:layout_paddingLeft=""; 离父元素左边缘的距离
- android:layout_paddingRight ="";离父元素右边缘的距离
- android:layout_paddingTop=""; 离父元素上边缘的距离
— — — — — — — — 华丽的分割线 — — — — — — — — xml
绝对布局
绝对布局(AbsoluteLayout)能经过指定的界面元素的坐标位置,来肯定用户界面的总体布局。绝对布局是一种不推荐使用的布局(下降了界面布局对不一样类型和尺寸屏幕的适应能力)。每个界面控件都要指定坐标 (X,Y)。class
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_x="89dp"
android:layout_y="93dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />