您的位置:首页 > 其它

RelativeLayout初步了解

2015-10-14 00:35 344 查看
特点:按组件的相对位置来多布局,如某个组件在某个组件的上下左右。常用属性:
XML属性描述
android:layout_above指定该组件在某个组件上方
android:layout_below指定该组件在某个组件下方
android:layout_toLeftOf指定该组件在某个组件左边
android:layout_toRightOf指定该组件在某个组件的右边
android:layout_centerInParent指定该组件在父组件的中间
android:layout_centerVertical垂直居中
android:layout_centralHorizontal水平居中
android:layout_alignRight指定这个组件和哪个组件左边对齐
android:layout_alignLet指定这个组件和哪个组件右边对齐
android:layout_alignBottom指定这个组件和哪个组件底端对齐
android:layout_alignTop指定这个组件和哪个组件顶端对齐
android:layout_alignParentRight用于指定该组件是否与父控件右端对齐
android:layout_alignParentLeft指定该组件是否与父控件左端对齐
android:layout_alignParentTop指定该组件是否与父控件顶端对齐
android:layout_alignParentDown指定该组件是否与父控件下面对齐
代码示意:
<?xmlversion="1.0"encoding="utf-8"?>
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btn_center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="中"/>
<Button
android:id="@+id/btn_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/btn_center"
android:layout_alignLeft="@+id/btn_center"
android:text="上"/>
<Button
android:id="@+id/btn_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_center"
android:layout_centerHorizontal="true"
android:text="下"/>
<Button
android:id="@+id/btn_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/btn_center"
android:text="左"/>
<Button
android:id="@+id/btn_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btn_center"
android:layout_toRightOf="@+id/btn_center"
android:text="右"/>
</RelativeLayout>
<?xmlversion="1.0"encoding="utf-8"?>
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btn_center1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="中"/>
<Button
android:id="@+id/btn_left1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/btn_center1"
android:text="左"/>
<Button
android:id="@+id/btn_right1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btn_left1"
android:layout_alignParentRight="true"
android:text="右"/>
<Button
android:id="@+id/btn_left2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_center1"
android:text="左"/>
<Button
android:id="@+id/btn_right2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btn_left2"
android:layout_alignParentRight="true"
android:text="右"/>
</RelativeLayout>

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: