Relative Layout佈局:相對位置佈局,的幾個重要屬性 android
第一類 : 屬性值爲 true 或 false 佈局
第二類:屬性值必須爲 id 的引用名「 @id/id-name 」 spa
第三類:屬性值爲具體的像素值,如 30dip , 40px code
Relative Layout佈局:相對位置佈局,相似於Word中的位置對齊,總共有九個方位,以下圖所示 xml
能夠分別對應Word中的九個方位,以及還能夠設置相似CSS中的組件與組件之間的外邊距,如margin便是設置這一項,注意layout_margin這一項設置像素之後,則是設置的上下左右四個方位的值,若是隻想設置某一邊的話,則使用下面的marginLeft……之一,
設置組件內文字與組件邊距可用屬性padding,以下圖: ip
下面,咱們來看看佈局文件的代碼與詳解 utf-8
<?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:layout_below="@id/label" android:background="@android:drawable/editbox_background" /> <Button android:id="@+id/ok" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_below="@id/entry" android:layout_marginLeft="10dip" android:text="OK" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@id/ok" android:layout_toLeftOf="@id/ok" android:text="Cancel" /> </RelativeLayout>
最後的效果圖爲: it
1.android:paddingLeft與android:layout_marginLeft的區別: io
padding margin都是邊距的含義,關鍵問題得明白是什麼相對什麼的邊距.
padding是控件的內容相對控件的邊緣的邊距.
layout_margin是控件邊緣相對父空間的邊距. class
2.android: gravity和android:layout_gravity區別
android:gravity 屬性是對該view 內容的限定.好比一個button 上面的text. 你能夠設置該text 在view的靠左,靠右等位置.該屬性就幹了這個.
android:layout_gravity是用來設置該view相對與起父view 的位置.好比一個button 在linearlayout裏,你想把該button放在靠左靠右等位置就能夠經過該屬性設置.
這樣就解釋了,有什麼咱們弄個最外佈局,而後裏面包了幾個佈局,若是要使這幾個佈局都靠底,就能夠在最外佈局的屬性裏設置androi:gravity="botton" 由於gravity是對裏面的內容起做用.