網格佈局管理器
在佈局管理器上所設置的屬性
android:columnCount
最大幾列
android:orientation
排布方式
android:rowCount
最大幾行
android:columnCount="2"
android:rowCount="2"
在佈局管理器的組件上所設置的屬性
GridLayout.LayoutParams
android:layout_column
列位置
android:layout_columnSpan
列橫跨
android:layout_columnWeight
列權重
android:layout_gravity
android:layout_ row
android:layout_rowSpan
android:layout_rowWeight
android:layout_row="0"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_columnSpan="2"
android:layout_gravity="fill"
樣例
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#7841"
android:text="按鈕1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="1"
android:text="按鈕2"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#856485"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="1"
android:layout_column="0"
android:background="#8621"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:text="按鈕3"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#842365"
android:text="按鈕4"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="2"
android:layout_column="0"
android:layout_rowWeight="1"
android:layout_columnSpan="2"
android:text="按鈕5"
android:background="#985621"
android:layout_gravity="fill"
/>
</GridLayout>