Android入門 4種布局

2021-09-01 08:19:26 字數 1906 閱讀 2173

absolutelayout因為已被廢除,因此不做介紹;

只要存在介面,就會有布局的存在,就像swing,雖然乙個是桌面應用,乙個是手機應用,但是他們都差不多。

預設布局。元件的排列按照預先定義方向很有序的排列,類似於swing中的flowlayout;

注意點:

(1)可以在中新增android:orientation:vertical/horizontal ;

(2)可以巢狀;

每個元件都在左上角,如果多個元件一起出現,則會重疊,類似於git疊加的動畫;

每個元件定位都是按照與其他元件的上下、左右定位;

預設的定位為左上方;

(1)定位與元件的上下左右

android:layout_below="@id/.."

android:layout_above="@id/"

android:layout_toleftof="@id/"

android:layout_torightof="@id/"

(2)定位與元件的邊緣對齊

android:layout_alignleft="@id/"

android:layout_alignright="@id/"

android:layout_aligntop="@id/"

android:layout_alignbottom="@id/"

(3)定位與父元件的邊緣對齊

android:layout_alignparenttop="true"

android:layout_alignparentbottom="true"

android:layout_alignparentleft="true"

android:layout_alignparentright="true"

(4)與整個螢幕的關係

android:layout_centerhorizontal="true"

android:layout_centervertical="true"

android:layout_centerinparent="true"

(5)元件間的距離

android:layout_margintop="5dp"

android:layout_marginleft="5dp"

android:layout_marginright="5dp"

android:layout_marginbottom="5dp"

android:layout_margin="5dp"

類似於swing中的gridlayout;

**布局的每行用括起來;

在中可以定義如下屬性:

(1)android:shrinkcolumns="1" 表明第2個控制項如果裡面的內容過多,會收縮,擴充套件到第二行,而不是延伸;

(2)android:stretchcolumns="2" 如果有空白,第3個控制項填充;

在控制項中設定:

(1)android:layout_column="2" 將此控制項放在第3個位置;

(2)android:layout_span="2" 此控制項佔據2個單元位置;

Android入門 4種布局

absolutelayout因為已被廢除,因此不做介紹 只要存在介面,就會有布局的存在,就像swing,雖然乙個是桌面應用,乙個是手機應用,但是他們都差不多。預設布局。元件的排列按照預先定義方向很有序的排列,類似於swing中的flowlayout 注意點 1 可以在中新增android orien...

4 Android絕對布局

4 android絕對布局 布局的型別 android中的布局 1 線性布局 linearlayout 2 相對布局 relativelayout 3 布局 tablelayout 4 網格布局 gridlayout 5 層次布局 framelayout 6 絕對布局 absolutelayout ...

Android入門筆記 06 布局

android的五大布局分別是linearlayout 線性布局 framelayout 單幀布局 relativelayout 相對布局 absolutelayout 絕對布局 和tablelayout 布局 1 linearlayout 分為水平和垂直.通過 android orientatio...