標籤:android style blog http io ar color sp strong
概念
五大布局上一篇文章已經介紹了
LinearLayout
RelativeLayout
這一篇我們介紹剩下的三種布局
FrameLayout
五種布局中最佳單的一種布局。在這個布局在整個介面被當成一塊空白地區,所有的子項目不能放倒指定的位置,只能放到這個地區的左上方,並且後面的子項目會直接覆蓋前面的子項目。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ff000000" android:gravity="center" android:text="1" /> <TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ff654321" android:gravity="center" android:text="2" /> <TextView android:layout_width="50dp" android:layout_height="50dp" android:background="#fffedcba" android:gravity="center" android:text="3" /></FrameLayout>
上面的布局檔案的效果:
第一個TextView被第二個TextView完全遮擋,第三個TextView遮擋了第二個TextView的部分位置
AbsoluteLayout 絕對位置布局
顧名思義,在此布局在子項目的android:layout_x和android:layout_y屬性將生效,用於描述該子項目的座標位置。螢幕左上方為座標原點(0,0),第一個0代表橫座標,向右移動此值增大,第二個0代表縱座標,向下移動,此值增大。在此布局中的子項目可以相互重疊。在實際開發中,通常不採用此布局格式,因為它的介面代碼過於剛性,以至於有可能不能很好的適配各種終端。
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="50dp" android:layout_height="50dp" android:layout_x="50dp" android:layout_y="50dp" android:background="#ff11ffff" android:gravity="center" android:text="1" /> <TextView android:layout_width="50dp" android:layout_height="50dp" android:layout_x="25dp" android:layout_y="25dp" android:background="#ff654321" android:gravity="center" android:text="2" /> <TextView android:layout_width="50dp" android:layout_height="50dp" android:layout_x="125dp" android:layout_y="125dp" android:background="#fffedcba" android:gravity="center" android:text="3" /></AbsoluteLayout>
顯示效果如下:
TableLayout 表格版面配置
適用於N行N列的布局方式。一個TableLayout由許多TableRow組成,一個TableRow就代表TableLayout中的一行。
TableRow是LinearLayout的子類,它的android:orientation屬性值恒為horizontal,並且它的android:layout_width和android:layout_height屬性值恒為MATCH_PARENT和WRAP_CONTENT。
所以它的子項目都是橫向排列,並且寬高一致的。
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" > <TextView android:background="#ff11ffff" android:gravity="center" android:padding="10dp" android:text="1" /> <TextView android:background="#ff654321" android:gravity="center" android:padding="10dp" android:text="2" /> <TextView android:background="#fffedcba" android:gravity="center" android:padding="10dp" android:text="3" /> </TableRow> <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" > <TextView android:background="#ff654321" android:gravity="center" android:padding="10dp" android:text="2" /> <TextView android:background="#fffedcba" android:gravity="center" android:padding="10dp" android:text="3" /> </TableRow> <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" > <TextView android:background="#fffedcba" android:gravity="center" android:padding="10dp" android:text="3" /> <TextView android:background="#ff654321" android:gravity="center" android:padding="10dp" android:text="2" /> <TextView android:background="#ff11ffff" android:gravity="center" android:padding="10dp" android:text="1" /> </TableRow></TableLayout>
這樣的設計使得每個TableRow裡的子項目都相當於表格中的儲存格一樣。
在TableRow中,儲存格可以為空白,但是不能跨列。
下面樣本示範了一個TableLayout的布局結構,其中第二行只有兩個儲存格,而其餘行都是三個儲存格。
【Android開發學習筆記】【第七課】五大布局-下