Android layout manager (table layout) and android Layout
Table layout is represented by TableLayout. TableLayout inherits LinearLayout, so its essence is still LinearLayout.
The table layout is managed in the form of rows and columns. You do not need to declare the number of rows and columns when using the table layout. Instead, you can add TableRow and other components to control the number of rows and columns of the table.
Each time you add a TableRow to TableLayout, The TableRow is a table row, and the TableRow is also a container. You can add other components continuously, each with a child component, this table adds a column.
In table layout manager, you can set the following three behavior methods for cells:
Because TableLayout inherits the LinearLayout class, in addition to all the attributes of LinearLayout, it also supports the following three attributes.
XMLAttribute |
Method |
Description |
Android: collapseColumns |
SetColumnCollapsed (int, boolean) |
Set the sequence number of the columns to be hidden. Multiple columns are separated by commas (,). |
Android: shrinkColumns |
SetShrinkAllColumns (boolean) |
Set the number of columns allowed to be shrunk. Separate multiple columns with commas (,). |
Android: stretchColumns |
SetStretchAllColumns (boolean) |
Set the sequence numbers of columns that can be stretched. Separate multiple columns with commas (,). |
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" xmlns: tools = "http://schemas.android.com/tools" android: layout_width = "fill_parent" android: layout_height = "fill_parent" android: orientation = "vertical" tools: context = "com. example. tablelayout. mainActivity "> <! -- The First TableLayout parameter specifies that two columns can be reduced, and three columns can be stretched --> <TableLayout android: id = "@ + id/tableLayout_one" android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: shrinkColumns = "1" android: stretchColumns = "3"> <Button android: id = "@ + id/ok1" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "Button on a single line"/> <TableRow> <Button android: id = "@ + id/ok2" android: layout_width = "Wrap_content" android: layout_height = "wrap_content" android: text = "normal Button"/> <Button android: id = "@ + id/ok3" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "contract Button"/> <Button android: id = "@ + id/ok4" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "stretch button"/> </TableRow> </TableLayout> <! -- The second TableLayout specifies that the two columns can be hidden --> <TableLayout android: id = "@ + id/tableLayout_two" android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: collapseColumns = "2"> <Button android: id = "@ + id/ok5" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "Button for a single row"/> <TableRow> <Button android: id = "@ + id/ok6" android: layout_width = "wrap_content" android: layout_heig Ht = "wrap_content" android: text = "normal Button"/> <Button android: id = "@ + id/ok7" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = ""/> <Button android: id = "@ + id/ok8" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "Hide button"/> </TableRow> </TableLayout> <! -- The third TableLayout parameter specifies that two columns can be stretched and three columns can be stretched --> <TableLayout android: id = "@ + id/tableLayout_three" android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: shrinkColumns = "1, 2"> <Button android: id = "@ + id/ok9" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "Button for a single row"/> <TableRow> <Button android: id = "@ + id/ok10" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "normal Button"/> <Button android: id = "@ + id/ok11" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "stretch Button"/> <Button android: id = "@ + id/ok12" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "stretch button"/> </TableRow> </TableLayout> </LinearLayout>