標籤:android blog http java io width re c
// 相對於給定ID控制項
android:layout_above 將該控制項的底部置於給定ID的控制項之上;
android:layout_below 將該控制項的底部置於給定ID的控制項之下;
android:layout_toLeftOf 將該控制項的右邊緣與給定ID的控制項左邊緣對齊;
android:layout_toRightOf 將該控制項的左邊緣與給定ID的控制項右邊緣對齊;
android:layout_alignBaseline 將該控制項的baseline與給定ID的baseline對齊;
android:layout_alignTop 將該控制項的頂部邊緣與給定ID的頂部邊緣對齊;
android:layout_alignBottom 將該控制項的底部邊緣與給定ID的底部邊緣對齊;
android:layout_alignLeft 將該控制項的左邊緣與給定ID的左邊緣對齊;
android:layout_alignRight 將該控制項的右邊緣與給定ID的右邊緣對齊;
// 相對於父組件
android:layout_alignParentTop 如果為true,將該控制項的頂部與其父控制項的頂部對齊;
android:layout_alignParentBottom 如果為true,將該控制項的底部與其父控制項的底部對齊;
android:layout_alignParentLeft 如果為true,將該控制項的左部與其父控制項的左部對齊;
android:layout_alignParentRight 如果為true,將該控制項的右部與其父控制項的右部對齊;
// 置中
android:layout_centerHorizontal 如果為true,將該控制項的置於水平置中;
android:layout_centerVertical 如果為true,將該控制項的置於垂直置中;
android:layout_centerInParent 如果為true,將該控制項的置於父控制項的中央;
// 指定移動像素
android:layout_marginTop 上位移的值;
android:layout_marginBottom 下位移的值;
android:layout_marginLeft 左位移的值;
android:layout_marginRight 右位移的值;
example:
android:layout_below = "@id/***"
android:layout_alignBaseline = "@id/***"
android:layout_alignParentTop = true
android:layout_marginLeft = “10px”
[java] view plaincopy
<?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:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Type here:"/>
<EditText
android:id="@+id/entry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/label"/>
<Button
android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/entry"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="OK" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/ok"
android:layout_alignTop="@id/ok"
android:text="Cancel" />
</RelativeLayout>
這是很常見的布局內容,講解如下:
android:layout_below="@id/label"/>
將當前控制項放置於id為label 的控制項下方。
android:layout_alignParentRight="true"
使當前控制項的右端和父控制項的右端對齊。這裡屬性值只能為true或false,預設false。
android:layout_marginLeft="10dip"
使當前控制項左邊空出相應的空間。
android:layout_toLeftOf="@id/ok"
使當前控制項置於id為ok的控制項的左邊。
android:layout_alignTop="@id/ok"
使當前控制項與id控制項的上端對齊。
至此,我們已經發現,其屬性之繁多。下面簡單歸納一下:
第一類:屬性值為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
備忘:原文出處http://www.cnblogs.com/hnrainll/archive/2012/03/28/2420901.html