標籤:android 線性布局 linearlayout
LinearLayout是線性布局控制項:要麼橫向排布,要麼豎向排布
決定性屬性:必須有的!
android:orientation:vertical (垂直方向) 、horizontal(水平方向)
常用屬性:
android:gravity------------設定的是控制項自身上面的內容位置
android:layout_gravity-----設定控制項本身相對於父控制項的顯示位置
android:layout_weight----- 給控制項分配剩餘空間
豎向排布執行個體:
<span style="font-family:Comic Sans MS;font-size:18px;"><?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" ><Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="按鈕1" /><Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="按鈕2" /><Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="按鈕3" /><Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="按鈕4" /></LinearLayout></span>
橫向排布執行個體:
<span style="font-family:Comic Sans MS;font-size:18px;"><?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" ><Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按鈕1" /><Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按鈕2" /><Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按鈕3" /><Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按鈕4" /></LinearLayout></span>
嵌套線性布局:
<span style="font-family:Comic Sans MS;font-size:18px;"><?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <LinearLayout > .. </LinearLayout> <LinearLayout> .. </LinearLayout> </LinearLayout></span>
Android【布局管理器】——線性布局LinearLayout