Tablelayout runs the way we use tables to arrange the controls, the essence of which is still the linear layout. Table layouts manage controls in the form of rows and columns, and Tablelayout does not require an explicit declaration of how many rows are included, but rather by adding tablerow, other components to control the number of rows and columns of the table.
Each time you add a tablerow to a table, the TableRow is a table row, and TableRow is also a container, so it can add additional components continuously, adding a column to the table for each child component.
Example code to implement a simple login interface
Tablelayout.xml
<?XML version= "1.0" encoding= "Utf-8"?><Tablelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:stretchcolumns= "1"> <TableRow> <TextViewAndroid:layout_height= "Wrap_content"Android:text= "Account:"/> <EditTextAndroid:id= "@+id/usernameinput"Android:layout_height= "Wrap_content"Android:hint= "Enter the user name to register"/> </TableRow> <TableRow> <TextViewAndroid:layout_height= "Wrap_content"Android:text= "Password:"/> <EditTextAndroid:id= "@+id/passwordinput"Android:layout_height= "Wrap_content"Android:hint= "Input to Password"/> </TableRow> <TableRow> <ButtonAndroid:id= "@+id/loginbutton"Android:layout_height= "Wrap_content"Android:layout_span= "2"Android:text= "Login"/> </TableRow></Tablelayout>
The results shown are:
Obviously, it's ugly, we want to have a certain amount of space between the left and right sides, and all of the components are in the middle of the screen, and there are some properties that need to be combined to achieve these effects.
android:collapsecolumns= "0"--Hide No. 0 column
android:shrinkcolumns= "0"-Shrinking No. 0 column
android:stretchcolumns= "0"--Stretching the No. 0 column
Android Notes (ix) layout in Android-table layout