Android:控件布局(線性布局)LinearLayout


LinearLayout是線性布局控件:要么橫向排布,要么豎向排布

決定性屬性:必須有的!

android:orientation:vertical (垂直方向) 、horizontal(水平方向)

常用屬性:

android:gravity------------設置的是控件自身上面的內容位置

android:layout_gravity-----設置控件本身相對於父控件的顯示位置

android:layout_weight----- 給控件分配剩余空間

 

豎向排布實例:

<?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>

 

橫向排布實例:

<?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>

嵌套線性布局:

<?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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM