The code is as follows |
Copy Code |
<?xml version= "1.0" encoding= "Utf-8"?> <tablelayout xmlns:android= "Http://schemas.android.com/apk/res/android" Android:layout_width= "Fill_parent" android:layout_height= "Fill_parent" >
<TableRow> <textview android:text= "Column1" android:padding= "3dip"/> <textview android:text= "Column2" android:padding= "3dip"/> <textview android:text= "Column3" android:padding= "3dip"/> </TableRow>
<TableRow> <textview android:text= "Column11" android:visibility= "Invisible"/>//cell disappeared. <textview Android:text= "Invisible on the Left" Android:gravity= "Right" android:padding= "3dip"/> <button Android:id= "@+id/go" Android:text= "Go" android:padding= "3dip"/> <button Android:text= "Cancel" android:padding= "3dip"/> </TableRow>
<view//Spacer Line android:layout_height= "2dip" android:background= "#F00"/>
<TableRow> <textview android:text= "Cell Empty on the right"/> <textview Android:layout_column= "2" android:text= "Jump Open Empty Cell" android:padding= "3dip"/> </TableRow>
<TableRow> <textview android:text= "Merging 3 cells" Android:layout_span= "3" Android:gravity= "Center_horizontal" Android:background= "#FFC0C0C0" Android:textcolor= "#f00" android:padding= "3dip"/> </TableRow> </TableLayout> |
Tablelayout and TableRow is a group of collocation use of the layout, Tablelayout, TableRow in the tablelayout above, and button, TextView and other controls on the TableRow above, in addition, Tablelayout can also be placed on a separate control. Tablelayout is a complex layout, the simplest use is simply to drag the control to make an interface, but in practice, you often use tablelayout in your code, such as the effect of making a table. This article mainly introduces the basic use method of Tablelayout.
The properties that tablelayout often use are:
Android:collapsecolumns: Hides the specified column in the No. 0 behavior sequence:
Android:collapsecolumns This property is empty, the following figure:
Put the android:collapsecolumns=0,2 ———— – it means to remove columns No. 0 and 2nd, as shown below:
Android:shrinkcolumns: Automatically extends the specified columns to fill the available sections in the No. 0 behavior sequence:
The shrinkcolumns does not work when the controls inside the Layoutrow are not yet covered, as shown in the following figure:
Set the shrinkcolumns=0,1,2, the layout is completely unchanged, because there is enough space in the Layoutrow.
When Layoutrow is full of controls, the following figure:
setting is set to shrinkcolumns=2, the result is that the control automatically fills the space vertically in the following illustration:
Android:stretchcolumns: In the No. 0 behavior sequence, try to fill the specified column with a blank part:
Set Stretchcolumns=1, the results are as follows, and the 1th column is filled as much as possible (BUTTON02 and TextView02 are filled right at the same time until TextView03 is squeeze to the last side).
Android's Tablelayout + TableRow is a bit complicated to use, but it's powerful ... Android offers a lot of layout properties, but the mobile app's interface isn't as fancy as a PC, so it's just a few of the things that are commonly used ...