Previous: http://www.bkjia.com/kf/201209/153078.html
TableLayout arranges its child views in the form of tables (rows and columns. A TableLayout can contain multiple TableRow objects. Each TableRow defines a row in the table (you can also use other types of child views). TableLayout does not display rows, columns, or cell boundary lines. Each row can contain 0 or more cells, and each cell can display a subview. The number of columns in the final table is determined by the row with the most cells. A table can contain empty cells, and cells can occupy multiple columns (similar to HTML ).
The column width depends on the cell in the column. However, TableLayout can specify the scaling attribute for some columns. If shrinkable is specified, this class can be reduced to adapt to the parent container. If stretchable is specified, the column can be stretched and filled with cells. The table width is determined by its parent container. The cell can specify both shrinkable and stretchable. In this case, the cell is always filled with View. You can call setColumnCollapsed () to hide a column ().
The layout_width attribute cannot be specified for the subview of TableLayout. Its value is always MATCH_PARENT, while layout_height can be specified. The default value is WRAP_CONTENT. If the subview type of TableLayout is TableRow, The layout_height is.
Cells must be added to each row in sequence (XML or code). The column sequence number starts from 0. If no class sequence number is specified for the cell, it is automatically added to the next column, if a column is skipped, The skipped class is considered as a null cell.
If TableRow is not used as a subclass of TableLayout, the View in this row is considered to occupy all columns.
This example shows the basic usage of TableLayout. TableRow is used to define three rows. Each row has three textviews, and the column width of each column is determined by the widest cell of the column:
[Html]
<TableLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent">
<TableRow>
<TextView
Android: text = "@ string/table_layout_1_star"
Android: padding = "3dip"/>
<TextView
Android: text = "@ string/table_layout_1_open"
Android: padding = "3dip"/>
<TextView
Android: text = "@ string/table_layout_1_open_shortcut"
Android: padding = "3dip"/>
</TableRow>
<TableRow>
<TextView
Android: text = "@ string/table_layout_1_triple_star"
Android: padding = "3dip"/>
<TextView
Android: text = "@ string/table_layout_1_save"
Android: padding = "3dip"/>
<TextView
Android: text = "@ string/table_layout_inclusave_shortcut"
Android: padding = "3dip"/>
</TableRow>
<TableRow>
<TextView
Android: text = "@ string/table_layout_1_star"
Android: padding = "3dip"/>
<TextView
Android: text = "@ string/table_layout_1_quit"
Android: padding = "3dip"/>
<TextView
Android: text = "@ string/table_layout_1_quit_shortcut"
Android: padding = "3dip"/>
</TableRow>
</TableLayout>
<TableLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent">
<TableRow>
<TextView
Android: text = "@ string/table_layout_1_star"
Android: padding = "3dip"/>
<TextView
Android: text = "@ string/table_layout_1_open"
Android: padding = "3dip"/>
<TextView
Android: text = "@ string/table_layout_1_open_shortcut"
Android: padding = "3dip"/>
</TableRow>
<TableRow>
<TextView
Android: text = "@ string/table_layout_1_triple_star"
Android: padding = "3dip"/>
<TextView
Android: text = "@ string/table_layout_1_save"
Android: padding = "3dip"/>
<TextView
Android: text = "@ string/table_layout_inclusave_shortcut"
Android: padding = "3dip"/>
</TableRow>
<TableRow>
<TextView
Android: text = "@ string/table_layout_1_star"
Android: padding = "3dip"/>
<TextView
Android: text = "@ string/table_layout_1_quit"
Android: padding = "3dip"/>
<TextView
Android: text = "@ string/table_layout_1_quit_shortcut"
Android: padding = "3dip"/>
</TableRow>
</TableLayout>