Android中的相對佈局基礎知識

1、基本屬性
gravity :設置容器內組件的對齊方式
ignoreGravity : 設置該屬性爲true的組件,將不受gravity屬性的影響

2、根據父容器定位
layout_alignParentLeft : 左對齊
layout_alignParenRight : 右對齊
layout_alignParentTop : 頂部對齊
layout_alignParentButtom : 底部對齊
android:layout_centerHorizontal :水平居中
android:layout_centerVertical : 垂直居中
android:layout_centerInParent : 中間位置

3、根據兄弟組件定位
layout_toLeftOf : 參考組件的左邊
layout_toRightOf: 參考組件的左邊
layout_above : 參考組件的上方
layout_below : 參考組件的下方
layout_alignTop :對齊參考組件的上邊界
layout_alignBottom : 對齊參考組件的下邊界
layout_alignLeft: 對齊參考組件的左邊界
layout_alignRight : 對齊參考組件的右邊界

4、margin(偏移)
設置組件與父容器的邊界
layout_margin 設置組件上下左右的偏移量
layout_marginLeft 設置組件離左邊的偏移量
layout_marginRight 設置組件離右邊的偏移量
layout_marginTop 設置組件離上面的偏移量
layout_marginButtom 設置組件離下面的偏移量

5、padding(填充)
設置組件內部元素間的邊距(比如TextView裏的字體位置)
android:padding 往內部元素的上下左右填充一定邊距
paddingLeft 往內部元素的左邊填充一定邊距
paddingRight 往內部元素的右方填充一定邊距
paddingTop 往內部元素的上方填充一定邊距
paddingBottom 往內部元素的下發填充一定邊距

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