標籤:android style blog http io ar 使用 sp java
3、TableLayout(表格版面配置)
像表格一樣布局,通常情況下,TableLayout有多個TableRow組成,每個TableRow就是一行。
<?xml version="1.0" encoding="utf-8"?><TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:shrinkColumns="2"> <TableRow> <Button android:text="Button1"/> <Button android:text="Button2"/> <Button android:text="Button3"/> </TableRow> <TableRow> <Button android:text="Button4"/> <Button android:text="Button5"/> <Button android:text="Button6"/> </TableRow> <TableRow> <Button android:text="Button7"/> <Button android:text="Button8"/> <Button android:text="Button9"/> </TableRow></TableLayout>
總結:常用屬性:
[1]shrinkColumns屬性:以0行為序,當TableRow裡面的控制項布滿布局時,指定列自動延伸以填充可用部分;當TableRow裡面的控制項還沒有布滿布局時,shrinkColumns不起作用。(android:shrinkColumns="2",第3列布滿時填充)
[2]strechColumns屬性:以第0行為序,指定列對空白部分進行填充。(android:strechColumns="2",第3列填充)
[3]collapseColumns屬性:以0行為序,隱藏指定的列.。(android:strechColumns="2",隱藏第3列)
[4]layout_column屬性:以0行為序,設定組件顯示指定列。(android:layout_column="2",顯示在第三列)
[5]layout_span屬性:以第0行為序,設定組件顯示佔用的列數。(android:layout_span="3",佔用3列)
4、AbsoluteLayout(絕對布局)
組件的位置可以準確的指定其在螢幕的x/y座標位置。雖然可以精確的去規定座標,但是由於代碼的書寫過於剛硬,使得在不同的裝置,不同解析度的手機行動裝置上不能很好的顯示應有的效果,所以此布局不怎麼被推薦使用。
<?xml version="1.0" encoding="utf-8"?><AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:layout_width="wrap_content" android:layout_height="fill_parent" android:text="Button1" android:layout_x="100dp" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Button2" android:layout_y="100dp" /> </AbsoluteLayout>
5、FrameLayout(單幀布局)
據說是五種布局中最簡單的一種,因為單幀布局在新定義組件的時候都會將組件放置螢幕的左上方,即使在此布局中定義多個組件,後一個組件總會將前一個組件所覆蓋,除非最後一個組件是透明的。
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Button1" /> <Button android:layout_width="wrap_content" android:layout_height="fill_parent" android:text="Button2" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button3" /> </FrameLayout>
Android 之布局(二)