按行或按列單個顯示,主要屬性如下:
相對於某一個元素
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的佈局和視圖可以參考這篇博文點擊打開鏈接。寫的非常全!