Android 4, Ice Cream Sandwich (ICS) API Level 14, 提供新的的網格佈局(GridLayout). 注意, 網格佈局(GridLayout)不同於網格視圖(GridView). 下面是一個網格佈局的簡單例子.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<GridLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:useDefaultMargins="true"
android:columnCount="4"
android:rowCount="3"
>
<TextView
android:background="@android:color/background_light"
android:text="A"/>
<TextView
android:layout_column="1"
android:layout_row="0"
android:background="@android:color/background_light"
android:text="B"/>
<ImageView
android:layout_column="2"
android:layout_row="0"
android:background="@android:color/background_light"
android:src="@drawable/ic_launcher"/>
<TextView
android:layout_column="3"
android:layout_row="0"
android:background="@android:color/background_light"
android:text="D"/>
<TextView
android:layout_column="1"
android:layout_row="1"
android:text="F"/>
<TextView
android:text="G"/>
<TextView
android:text="H"/>
<Button
android:layout_columnSpan="3"
android:text="I, J, K"/>
<TextView
android:text="L"/>
</GridLayout>
</LinearLayout>
Android Developers Blog上有一編講解網格佈局很好的文章.

沒有留言:
發佈留言