当前位置:操作系统 > 安卓/Android >>

RelativeLayout布局常用属性

 

先看一下一个布局文件例子:

 

<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、

 

摘自 wxg630815的专栏

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,