The number of rows for a tablelayout is specified directly by the developer, that is, how many TableRow objects (or view controls) there are.
The number of columns of tablelayout equals the number of columns of TableRow that contain the most child controls. If the first TableRow contains 2 child controls, the second TableRow contains 3, and the third TableRow contains 4, then the Tablelayout has a number of 4 columns.
Tablelayout properties that can be set include global properties and cell properties.
1, global properties, or column properties, have the following 3 parameters:
android:stretchcolumns Sets columns that can be stretched . The column can stretch to line direction , which can occupy up to a full row.
android:shrinkcolumns Sets the column that can be shrunk . When the column control has too much content and is already packed in the row, the contents of the child control are displayed in the columns direction.
Android:collapsecolumns sets the columns to hide .
example:
android:stretchcolumns= "0" No. 0 column to extend
android:shrinkcolumns= 1th, 2 columns can be shrunk
android:collapsecolumns= " * " Hide all rows
Description: The column can have both Stretchcolumns and Shrinkcolumns properties, if so, Then when the column has more than N, "multiline" displays its contents. (This is not really a multiline, but the system automatically adjusts the line's layout_height as needed)
2, cell properties, have the following 2 parameters:
Android:layout_column specifies that the cell is displayed in the first column
Android:layout_span Specifies the number of columns that the cell occupies (when unspecified, 1)
Example:
android:layout_column= "1" The control is displayed in the 1th column
Android:layout_span= "2" This control occupies 2 columns
Description: A control can also have both features .
Tablelayout is a complex layout, the simplest use is simply to drag the control to make an interface, but in fact, often in the code to use the Tablelayout, for example, to make a table effect. This article mainly introduces the basic use method of Tablelayout.
<?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>
<button
Android:id= "@+id/button1"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "Button1"
android:layout_column= "0"/>
<button
Android:id= "@+id/button2"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:text= "Hello, I am a Button2"
android:layout_column= "1"/>
</TableRow>
</TableLayout>
1 android:stretchcolumns = "specified column"-------> to fill the specified column with a blank part in the No. 0 action order
Set stretchcolumns=0, the result is as follows, the No. 0 column is populated as far as possible
Set Stretchcolumns=1, the result is as follows, the 1th column is populated as far as possible
2 Android:shrinkcolumns = "specified column": Automatically extends the specified column to fill the available parts with the No. 0 action order
Shrinkcolumns does not work when the controls inside the Layoutrow are not covered by the layout, such as
When the controls inside the Layoutrow are not covered by the layout (rewrite the contents of the third button)
3 Android:collapsecolumns = "specified column" No. 0 sequence, hides the specified column >
Android:collapsecolumns when this property is empty, such as:
android:collapsecolumns= "0" means to remove the No. 0 column, such as:
Citation:http://blog.csdn.net/zj0078/article/details/7390505
Android--tablelayout