网格布局管理器
在布局管理器上所设置的属性
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>