1、LinearLayout(線性佈局)
LinearLayout主要屬性:orientation(排列方向) weight(權重)
orientation(排列方向) :主要分horizontal(水平)和vertical(垂直)
weight(權重):主要用在0dp、wrap_content、match_parent情況下。
horizontal情況下,設置內部view的width爲0dp或wrap_content,然後通過weight設置比例,vertical同理;
horizontal情況下,設置內部view的width爲match_parent,然後通過weight設置比例(計算方法,如1:2:3,比例就是1/6,2/6,3/6,每項計算類似1-2*(1/6),結果是2:1:0 ),vertical同理;
假設width=480 父控件剩餘寬度rest=480-480*3(分三塊)=-480*2
計算方法:控件寬度+父控件剩餘寬度*比例
tv1=480-(480*2)*(1/6)=480*(4/6)
tv2=480-(480*2)*(2/6)=480*(2/6)
tv3=480-(480*2)*(3/6)=480*(0/6)
例子:
2、RelativeLayout(相對佈局)
根據父容器定位或兄弟組件定位
RelativeLayout主要屬性:
layout_centerInParent(居中)
layout_centerHorizontal(水平居中) layout_centerVertical(垂直居中)
layout_above(控件上方)layout_below(控件下方)
layout_toLeftOf (控件左邊) layout_toRightOf(控件右邊)
注意:margin是偏移,針對容器中的組件;padding是填充,針對組件中的元素
簡單來說margin爲外邊框,border爲邊框,padding爲內邊框
例子:
3、TableLayout(表格佈局)
TableLayout主要屬性:
collapseColumns(隱藏列) stretchColumns(拉伸列) shrinkColumns(收縮列)
例子:
4、FrameLayout(幀佈局)
FrameLayout主要屬性:foreground(前景圖像) foregroundGravity(前景圖像位置)
例子:
5、GridLayout(網格佈局)
GridLayout主要屬性:
columnCount rowCount(佈局行列數) layout_columnSpan layout_rowSpan(組件橫跨)
例子:
6、AbsoluteLayout(絕對佈局)
AbsoluteLayout主要屬性:layout_x和layout_y
例子:
https://github.com/xian131/LittleDemoAndroid/tree/master/Test01Layout