1. Related attributes
1.1, Common Properties android:collapsecolumns set the sequence number of the column that needs to be hidden Android:shrinkcolumns set the serial number of the column that is allowed to be shrunk Android:stretchcolumns set the serial number of the column that is being stretched Note: The column number is calculated from 0, set multiple "1,3", all columns take effect "*" = "2" means skip the second = "4" means merging 4 cells 1.2, how to determine the number of rows and columns ! How to add components directly to Tablelayout, that component will fill up the line ! How to think of multiple components in a row, add a TableRow container and put the components in ! The number of components in the TableRow determines the column count, and the width of the column is determined by the widest cell ! TableRow width is the default cannot be modified, height can be customized ! The width of the entire table layout depends on the width of the parent container
2. Example
<?XML version= "1.0" encoding= "Utf-8"?><Tablelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Tools:context=". Loginactivity "Android:stretchcolumns= "0,3"android:gravity= "Center_vertical"Android:background= "#66ff66"> <TableRow> <TextView/> <TextViewAndroid:layout_height= "Wrap_content"Android:text= "User name:"/> <EditTextAndroid:layout_height= "Wrap_content" /> <TextView/> </TableRow> <TableRow> <TextView/> <TextViewAndroid:layout_height= "Wrap_content"Android:text= "Password"/> <EditTextAndroid:layout_height= "Wrap_content"Android:minwidth= "200DP"/> <TextView/> </TableRow> <TableRow> <TextView/> <ButtonAndroid:layout_height= "Wrap_content"Android:text= "Login"/> <ButtonAndroid:layout_width= "60DP"Android:text= "Exit"/> <TextView/> </TableRow></Tablelayout>
Android tablelayout Table layout