TableLayout表格布局以行列的形式管理子控件,每一行为一个TableRow的对象,固然也能够是一个View的对象。android
android:collapseColumns="1,2" --隐藏从0开始的索引列,列直接、必须用逗号隔开:1,2,5 android:shrinkColumns="1,2" --收缩从0开始的索引列,当可收缩的列太宽(内容过多)不会被挤出屏幕,列直接必须用逗号隔开:1,2,5,你能够用"*"代替收缩全部列。注意一列能同时表示收缩和拉伸。 android:stretchColumns="1,2" --拉伸从0开始的索引列,以填满剩下的多余空白空间,列直接必须用逗号隔开:1,2,3,你能够用"*"代替收缩全部列。注意一列能同时表示收缩和拉伸。
1.android:collapseColumns布局
实例:spa
<?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.demo4.MainActivity"> <TableRow android:id="@+id/row1" android:layout_width="wrap_content" android:layout_height="wrap_content" > <Button android:text="1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button" /> <Button android:text="2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button2" /> <Button android:text="3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button3" /> </TableRow> </TableLayout>
界面以下:code
添加TableLayout中添加属性:xml
android:collapseColumns="0"
结果是将第0列隐藏了对象
2.android:stretchColumns索引
添加:utf-8
android:stretchColumns="2"
3.android:shrinkColumnsit
加长button3的文字:io
在属性中添加:
android:shrinkColumns="2"
能够看到收缩效果:
android:layout_column="1" --该控件显示在第2列 android:layout_span="2" --该控件占据2列