I haven't learned any more in a week. I don't need to talk much nonsense. I just need to go to the XML file code:
<? 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"> </P> <p> <tablerow> <br/> <textview <br/> Android: layout_column = "1" <br/> Android: text = "open... "<br/> Android: padding =" 3dip "/> <br/> <textview <br/> Android: text =" Ctrl-o "<br/> Android: gravity = "right" <br/> Android: padding = "3dip"/> <br/> </tablerow> </P> <p> <tablerow> <br/> <textview <br/> Android: layout_column = "1" <br/> Android: text = "save... "<br/> Android: padding =" 3dip "/> <br/> <textview <br/> Android: text =" Ctrl-s "<br/> Android: gravity = "right" <br/> Android: padding = "3dip"/> <br/> </tablerow> </P> <p> <tablerow> <br/> <textview <br/> Android: layout_column = "1" <br/> Android: text = "Save... "<br/> Android: padding =" 3dip "/> <br/> <textview <br/> Android: TEXT = "Ctrl-shift-s" <br/> Android: gravity = "right" <br/> Android: padding = "3dip"/> <br/> </tablerow> </P> <p> <view <br/> Android: layout_height = "2dip" <br/> Android: background = "# ff909090"/> </P> <p> <tablerow> <br/> <textview <br/> Android: TEXT = "X" <br/> Android: padding = "3dip"/> <br/> <textview <br/> Android: text = "import... "<br/> Android: padding = "3dip"/> <br/> </tablerow> </P> <p> <tablerow> <br/> <textview <br/> Android: TEXT = "X" <br/> Android: padding = "3dip"/> <br/> <textview <br/> Android: text = "Export... "<br/> Android: padding =" 3dip "/> <br/> <textview <br/> Android: text =" Ctrl-e "<br/> Android: gravity = "right" <br/> Android: padding = "3dip"/> <br/> </tablerow> </P> <p> <view <br/> Android: layout_height = "2dip" <br/> Android: background = "# ff909090"/> </P> <p> <tablerow> <br/> <textview <br/> Android: layout_column = "1" <br/> Android: text = "quit" <br/> Android: padding = "3dip"/> <br/> </tablerow> <br/> </tablelayout> |
Note: This is similar to the structure of an HTML table.
Tablelayout is similar to the table of HTML elements;
Tablerow is similar to the TR of HTML elements;
However, for cells, you can use any component. In this example, a textview is equivalent to a cell.
The view between tablerow and tablerow is used to draw a horizontal line.
Tablelayout xmlns: Android = "http://schemas.android.com/apk/res/android" // indicates that this activity uses table layout
Android: layout_width = "fill_parent" // adaptive width
Android: layout_height = "fill_parent" // adaptive height
Android: stretchcolumns = "1" // sets the second column of all rows in tablelayout as an extension column. That is to say, if each row has three columns, the remaining space is filled by the second column.
The first line: Line 1: <br/> <tablerow> <br/> <textview <br/> Android: Background = "# 3300cc" // background color <br/> Android: layout_column = "0" // cell index. 0 is the first <br/> Android: text = "open... "// content <br/> Android: padding =" 3dip "/> // margin between components <br/> <textview <br/> Android: background = "#996600" <br/> Android: text = "Ctrl-o" <br/> Android: gravity = "right" // specifies how to align text, because the cell is too wide, you must specify <br/> Android: padding = "3dip"/> <br/> </tablerow> Android: layout_column = "0" // cell index. 0 indicates the first index. The experiment shows that the table layout in Android is not as fixed as the table in the webpage. You can merge cells, but the number of columns here is not fixed, if you set it to 0, this component is arranged in the first column. If you set it to 1, an additional column is automatically located in the second column. I changed it like this: <Tablerow> <br/> <textview Android: layout_column = "0" Android: text = "open... "Android: padding =" 3dip "Android: Background =" # FFFF00 "/> </P> <p> <textview Android: layout_column =" 3 "<br/> Android: TEXT = "Ctrl-o" Android: gravity = "right" Android: padding = "3dip" Android: Background = "#660000"/> <br/> </tablerow> The table is automatically changed to four columns. Here, If you want four columns on a webpage, unlike the HTML table <Table> <br/> <tr> <br/> <TD> 1 </TD> <br/> <TD> 2 </TD> <br/> <TD> 3 </TD> <br/> <TD> 4 </TD> <br/> </tr> <br/> </table> <br/> In Android, however <Table> <br/> <tr> <br/> <TD layout_column = 0> </TD> <br/> <TD layout_column = 4> </TD> <br /> </tr> <br/> </table> <br/> In this way, the four columns are implemented, and their columns are determined based on the column subscript. Therefore, pay attention to this point during layout. |
Let's explain it elsewhere.
<View <br/> Android: layout_height = "2dip" <br/> Android: Background = "# ff909090"/>
A line is equivalent to <HR/> Android: padding = "3dip" is equivalent to the padding attribute in CSS in HTML. It refers to the content in the container and the margin of the container. However, here we do not use PX as the unit, but dip as the unit, pay attention to it. |