A06_RelativeLayout的屬性設置

設有兩個控件one和two,以控件one爲基準。由於代碼比較簡單就不貼了,直接上效果圖。

一、第一組:將控件two放在控件one的上、下、左、右、開始、結束。

        android:layout_below=""
        android:layout_above=""
        android:layout_toLeftOf=""
        android:layout_toRightOf=""
        android:layout_toStartOf="" 開始
        android:layout_toEndOf="" 結束

由於one控件的位置固定不做變動,two控件在它上方和左邊的位置就無法顯示出來,效果是隻有one控件,不再演示。

圖一:android:layout_above 


圖二:android:layout_toRightOf 


圖三:android:layout_toEndOf(可以看出效果和layout_toRightOf一樣,類似layout_toStartOf和layout_toLeftOf效果一樣)


二、第二組:align是“對齊”的意思。將控件two和控件one的上邊、下邊、左邊、右邊對齊。

android:layout_alignLeft=""左邊對齊
        android:layout_alignRight="" 右邊對齊
        android:layout_alignTop="" 上邊對齊
        android:layout_alignBottom="" 下邊對齊

圖一:android:layout_alignLeft

 

圖二:android:layout_alignBottom(底邊對齊)

  
三、第三組 :將控件two和父控件(認爲佈局也是控件)的頂部、底部、左邊、右邊對齊 。將控件two和控件one的基線對齊
       

android:layout_alignParentLeft=""和父控件的左邊對齊

        android:layout_alignParentRight="" 和父控件的右邊對齊
        android:layout_alignParentTop="" 和父控件的頂部對齊
        android:layout_alignParentBottom="" 和父控件的底部對齊

android:layout_alignBaseline="" 控件two和控件one的基線對齊



圖一:android:layout_alignParentLeft:

圖二:android:layout_alignParentBottom


圖三:android:layout_alignBaseline:圖中綠色的水平線就是基線,爲了更清楚的顯示基線,對Two控件還添加了android:layout_toRightOf屬性。



基線解釋:書寫英語單詞時爲了規範書寫會設有四條線,從上至下第三條就是基線。基線對齊主要是爲了兩個控件中顯示的英文單詞的基線對齊。


四、第四組:中心對齊。值爲true/false        
        android:layout_centerInParent="" 父控件中心對齊
        android:layout_centerHorizontal="" 水平中興對齊
        android:layout_centerVertical="" 垂直中興對齊


圖一:android:layout_centerInParent: 

           

圖二:android:layout_centerHorizontal:   

   

圖三:android:layout_centerVertical:


五、第五組:android4.2新增屬性。控件one和控件two開始對齊、結束對齊。控件one和父控件開始對齊、結束對齊。
        android:layout_alignStart="" 兩個控件開始對齊
        android:layout_alignEnd="" 兩個控件結束對齊
        android:layout_alignParentStart="" 子控件和父控件開始對齊
        android:layout_alignParentEnd="" 子控件和父控件結束對齊

爲了便於顯示效果,在顯示layout_alignStart和layout_alignEnd屬性時,爲Two控件添加了layout_above屬性

圖一:android:layout_alignStart:

 

圖二:android:layout_alignEnd: 

   

圖三:android:layout_alignParentStart: 


圖四:android:layout_alignParentEnd


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章