android 开发布局之RelativeLayout
按行或按列单个显示,主要属性如下:
相对于某一个元素
android:layout_below="@id/aaa" 该元素在 id为aaa的下面
android:layout_toLeftOf="@id/bbb" 改元素的左边是bbb
相对于父元素
android:layout_alignParentLeft="true" 在父元素左对齐
android:layout_alignParentRight="true" 在父元素右对齐
还可以指定边距等,
android:layout_marginLeft="10dip"使当前控件左边空出相应的空间。
具体可以详见API,下面简单归纳一下其属性取值:
第一类:属性值为true或false
*android:layout_centerHrizontal
*android:layout_centerVertical
*android:layout_centerInparent
*android:layout_alignParentBottom
*android:layout_alignParentLeft
*android:layout_alignParentRight
*android:layout_alignParentTop
*android:layout_alignWithParentIfMissing
第二类:属性值必须为id的引用名“@id/id-name”
*android:layout_below
*android:layout_above
*android:layout_toLeftOf
*android:layout_toRightOf
*android:layout_alignTop
第三类:属性值为具体的像素值,如30dip,40px
*android:layout_marginBottom
*android:layout_marginLeft
*android:layout_marginRight
*android:layout_marginTop
如下布局:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/name_text" android:id="@+id/text" /> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/text" android:id="@+id/edit" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/cancle_button" android:layout_alignParentRight="true" android:layout_below="@id/edit" android:id="@+id/cancle" /> <Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_toLeftOf="@id/cancle"android:layout_alignTop="@id/cancle"android:text="@string/ok_button" /></RelativeLayout>显示的效果如下:
参考:http://hi.baidu.com/hoyah/item/ac49b0d059c96ae1b2f777f1
整个android的布局和视图可以参考这篇博文点击打开链接。写的非常全!
更多相关文章
- Android TextView 属性设置
- 安卓入门.RelativeLayout相对布局1
- Android中shape属性详解
- Android 控件及其属性2
- Android属性之android:priority