您的位置:首页 > 移动开发 > Android开发

[Android]RelativeLayout布局常用属性

2011-11-18 13:56 429 查看
先看一下一个布局文件例子:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="RelativeLayout 布局"
android:gravity="center_horizontal"
android:layout_centerHorizontal="true"
android:id="@+id/title"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="@id/title"
android:id="@+id/line"
android:background="#ffffff"
/>
<Button
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_below="@id/line"
android:id="@+id/btn_1"
android:layout_marginLeft="10dp"
android:text="Button One"
/>
<Button
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_below="@id/line"
android:id="@+id/btn_2"
android:layout_toRightOf="@id/btn_1"
android:text="Button Two"
/>

</RelativeLayout>


android:gravity="center_horizontal" 文字水平居中

android:layout_centerHorizontal="true"
组件水平居中,在相对布局中layout_gravity是不好使的,类似属性还有:android:layout_centerVertical="true"

android:layout_below="@id/title" 分割线位于标题(id=title)下边,类似的属性还有:android:layout_above

android:layout_toRightOf="@id/btn_1" 按钮2位于按钮1右边,类似的属性还有:android:layout_toLeftOf

android:layout_marginLeft="10dp" 组件距离父组件左边10dp,类似的属性还有android:layout_marginRight、android:layout_marginTop、android:layout_marginBottom、android:layout_margin
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: