The layout of tablelayout is roughly similar to that of linearlayout, but the differences between the two can be imagined. Those with development experience are certainly not familiar with table, here, tablelayout is actually a similar layout. The display mode on the mobile phone is similar to that on the website. Next I will first display the graph andCodeAnd then explain the important code.
The preceding figure shows a table with two rows and one column.
The following code is used:
Main. xml
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <tablelayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> Android: stretchcolumns = "1" <br/> <tablerow> <br/> <textview <br/> Android: TEXT = "@ string/row1_column1" <br/> Android: padding = "3dip"/> <br/> <textview <br/> Android: TEXT = "@ string/row1_column2" <br/> Android: gravity = "right" <br/> Android: padding = "3dip"/> <br/> </tablerow> </P> <p> <tablerow> <br/> <textview <br/> Android: TEXT = "@ string/row2_column1" <br/> Android: padding = "3dip"/> <br/> <textview <br/> Android: TEXT = "@ string/row2_column2" <br/> Android: gravity = "right" <br/> Android: padding = "3dip"/> <br/> </tablerow> <br/> </tablelayout>
In the above Code, it is worth noting that the tablerow label is used when a row is inserted in tablelayout, and Android: the stretchcolumns function means that if the content of a row cannot be filled with all layout, use the row number to pull up, and the starting value of stretching in Java starts from 0, so the code above is the second line. If you cannot see clearly, you can add the color of each line for identification. The method of adding a color is to use the Android: Background method in each line,
Padding indicates how far the margin is.