Android RelativeLayout屬性


// 相對於給定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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM