网格布局
自android4.0版本后新增的GridLayout网格布局的一些基本内容
GridLayout布局使用虚细线将布局划分为行,列和单元格,也支持一个控件在行,列上都有交错排列
GridLayout的布局策略简单分为以下三个部分:
与LinearLayout布局一样,也分为水平和垂直两种方式
默认是水平布局,一个控件挨着一个控件从左到右一次排列
通过指定android:columnCount设置列数的属性后,控件会自动换行进行排列
对于GridLayout布局中的子控件,默认按照wrap_content的方式设置其显示,这只需要在GridLayout布局中显式声明即可
GridLayout的布局策略简单分为以下三个部分:
1、若要指定某控件显示在固定的行或列
只需设置该子控件的android:layout_row和android:layout_column属性即可
需要注意:android:layout_row="0"表示从第一行开始
android:layout_column="0"表示从第一列开始
2、设置某控件跨越多行或多列
该子控件的android:layout_rowSpan或者layout_columnSpan属性设置为数值
设置其layout_gravity属性为fill即可
前一个设置表明该控件跨越的行数或列数,后一个设置表明该控件填满所跨越的整行或整列
http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="5"
android:orientation="horizontal" >
<
Button
android:text="1"
/>
<
Button
android:text="2"
/>
<
Button
android:text="3"
android:layout_row="1"
android:layout_column="1"
android:layout_columnSpan="2"
android:layout_gravity="fill"
/>
<
Button
android:text="4"
android:layout_row="0"
/>
<
Button
android:text="5"
/>
<
Button
android:text="6"
/>
http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content
android:columnCount="3">
<
ImageView
android:layout_row="0"
android:layout_column="0"
android:layout_rowSpan="2"
android:src="@drawable/ic_launcher"
/>
<
TextView
android:layout_row="0"
android:layout_column="1"
android:text="设置"
/>
<
TextView
android:layout_row="0"
android:layout_column="2"
android:text="44MB"
android:layout_gravity="right" />
<
TextView
android:layout_row="1"
android:layout_column="1"
android:text="一个文件"
android:layout_gravity="bottom"
/>
<
TextView
android:layout_row="1"
android:layout_column="2"
android:text="15:04"