Android - 常見的控件布局,左中右,左右等


這里匯總的是自己在工作過程中,使用過的常見空間布局,記錄在這里。詳情如下:

 

1. 三個控件,分別處於左,中,右

要點:使用RelativeLayout

 1     <RelativeLayout
 2                 android:layout_width="match_parent"
 3                 android:layout_height="wrap_content"
 4                 android:orientation="horizontal">
 5             <TextView
 6                     android:layout_width="wrap_content"
 7                     android:layout_height="wrap_content"
 8                     android:gravity="center"
 9                     android:layout_alignParentLeft="true"/>
10             <TextView
11                     android:layout_width="wrap_content"
12                     android:layout_height="wrap_content"
13                     android:gravity="center"
14                     android:layout_centerHorizontal="true"/>
15             <TextView
16                     android:layout_width="wrap_content"
17                     android:layout_height="wrap_content"
18                     android:gravity="center"
19                     android:layout_alignParentRight="true"/>
20     </RelativeLayout>

 

2. 兩個控件,分別處於左右

要點:使用layout_weight="1"的TextView撐開中間,將兩個控件擠到兩邊

 1         <LinearLayout
 2             android:layout_width="match_parent"
 3             android:layout_height="wrap_content"
 4             android:orientation="horizontal">
 5             <TextView
 6                     android:layout_width="wrap_content"
 7                     android:layout_height="wrap_content"
 8                     android:gravity="center"
 9                     android:layout_gravity="center"/>
10             <TextView
11                     android:layout_width="wrap_content"
12                     android:layout_height="wrap_content"
13                     android:layout_weight="1" />
14             <TextView
15                     android:layout_width="wrap_content"
16                     android:layout_height="wrap_content"
17                     android:gravity="center"
18                     android:layout_gravity="center"/>
19         </LinearLayout>

 

 

持續更新......


免責聲明!

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



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