什么是TableLayout
OK,关于Android之TableLayout布局的介绍就到这了。
表格布局是一个ViewGroup以表格显示它的子视图(view)元素,即行和列标识一个视图的位置。Android的表格布局跟HTML中的表格布局非常类似,TableRow 就像HTML表格的<tr>标记。
TableLayout常用的属性
android:collapseColumns:隐藏指定的列
android:shrinkColumns:收缩指定的列以适合屏幕,不会挤出屏幕
android:stretchColumns:尽量把指定的列填充空白部分
android:layout_column:控件放在指定的列
android:layout_span:该控件所跨越的列数
下面通过一个简单的例子实现其中的几个属性
先来分析一下:第一行的中间的按钮填充空白部分,第二行的第二个按钮放在右边列,第三行的第二个按钮横跨2列
代码如下
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1" >
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:text="Button11"/>
<Button
android:text="Button12"/>
<Button
android:text="Button13"/>
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:text="Button21"/>
<Button
android:layout_column="2"
android:text="Button23"/>
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:text="Button31"/>
<Button
android:layout_span="2"
android:text="Button33"/>
</TableRow>
</TableLayout>
OK,关于Android之TableLayout布局的介绍就到这了。