Android中的Table Layout
表格布局以表格行为基础,行内的一个UI元素为1列,可以设置一个UI元素跨多了在使用layout_span的属性。
- TableLayout - 表格式布局。
- TableRow - 表格内的行,行内每一个元素算作一列
- collapseColumns - 设置 TableLayout 内的 TableRow 中需要隐藏的列的列索引,多个用“,”隔开
- stretchColumns - 设置 TableLayout 内的 TableRow 中需要拉伸(该列会拉伸到所有可用空间)的列的列索引,多个用“,”隔开
- shrinkColumns - 设置 TableLayout 内的 TableRow 中需要收缩(为了使其他列不会被挤到屏幕外,此列会自动收缩)的列的列索引,多个用“,”隔开
2 <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:id="@+id/tablelayout1"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent"
6 android:collapseColumns="0,3">
7 <TableRow>
8 <TextView android:text="URL:"/>
9 <EditText android:id="@+id/url"
10 android:layout_span="3"/>
11 </TableRow>
12 <View
13 android:layout_height="2px"
14 android:background="#0000FF" />
15 <TableRow>
16 <Button android:id="@+id/cancel"
17 android:layout_column="2"
18 android:text="Cancel" />
19 <Button android:id="@+id/ok"
20 android:text="OK" />
21 </TableRow>
22 </TableLayout>
3 android:id="@+id/tablelayout1"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent"
6 android:collapseColumns="0,3">
7 <TableRow>
8 <TextView android:text="URL:"/>
9 <EditText android:id="@+id/url"
10 android:layout_span="3"/>
11 </TableRow>
12 <View
13 android:layout_height="2px"
14 android:background="#0000FF" />
15 <TableRow>
16 <Button android:id="@+id/cancel"
17 android:layout_column="2"
18 android:text="Cancel" />
19 <Button android:id="@+id/ok"
20 android:text="OK" />
21 </TableRow>
22 </TableLayout>
注意到EditText控件和ok按钮控件的列索引属性。因为EditText跨了3列,所以被隐藏了。
将想法付诸于实践,借此来影响他人是一个人存在的真正价值