Android layout ----- TableLayout (table layout) and tablelayout
Learning Map
(1) Introduction to TableLayout
Tables are often used in swing programming and html in java. It can be seen that many tables are used in application development. Similarly, android also provides us with such a layout method.
(2) how to determine the number of rows
A: directly to the TableLayout component and directly occupies a row
B: If you want to add multiple components in one row, you must use TableRow to add
C: The number of components in TableRow and the number of columns in this row
(3) three common attributes (all count from scratch)
Shrinkable: If a column is set to Shrinkable, the width of all cells in the column can be reduced to ensure that the table can adapt to the width of the parent container;
Stretchable: If a column is set to Stretchable, the width of all cells in the column can be stretched to ensure that the components fully fill the free space of the table;
Collapsed: If a column is set to Collapsed, all cells in the column will be hidden;
(4) use instances (no id is set for all components to demonstrate the effect)
<? Xml version = "1.0" encoding = "UTF-8"?> <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: layout_width = "match_parent" android: layout_height = "match_parent" android: orientation = "vertical"> <! -- Define the layout of the first table, specify that the second column can be reduced, and the third column can be stretched --> <TableLayout android: layout_width = "match_parent" android: layout_height = "wrap_content" android: shrinkColumns = "1" android: stretchColumns = "2"> <! -- Directly adding a component exclusive to a row --> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "occupying a single row"/> <TableRow> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "normal Button"/> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = ""/> <Button android: layout_width = "wrap_content" android: layout_he Ight = "wrap_content" android: text = "stretch button"/> </TableRow> </TableLayout> <! -- Define the second table layout and specify the second column to hide --> <TableLayout android: layout_width = "match_parent" android: layout_height = "wrap_content" android: collapseColumns = "1"> <! -- Directly adding a component exclusive to a row --> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "occupying a single row"/> <TableRow> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "normal Button"/> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "normal Button"/> <Button android: layout_width = "wrap_content" android: layout_he Ight = "wrap_content" android: text = "normal button"/> </TableRow> </TableLayout> <! -- Define the layout of the third table, specify the second column, and stretch the third column --> <TableLayout android: layout_width = "match_parent" android: layout_height = "wrap_content" android: stretchColumns = "1, 2"> <! -- Directly adding a component exclusive to a row --> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "occupying a single row"/> <TableRow> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "normal Button"/> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "stretch Button"/> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "stretch button"/> </TableRow> </TableLayout> </LinearLayout>