The label for the table layout is tablelayout,tablelayout inherited LinearLayout. So it's still a linear layout.
Objective:
1, Tablelayout Introduction
2, the determination of Tablelayout row number
3, Tablelayout can set the attribute detailed explanation
4. An example and effect diagram containing 4 tablelayout layouts
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/"
Android "android:orientation=" vertical "android:layout_width=" fill_parent "android:layout_height=" Fill_parent " android:padding= "3dip" > <!--1th tablelayout, which describes the column properties in the table. The No. 0 column can be stretched, the 1th column can be shrunk, the 2nd column is hidden--> <textview android:text= "Numeric Keypad" android:layout_height= "Wrap_content" Android:layout_ Width= "Wrap_content" android:textsize= "20sp" android:background= "#7f00ffff"/> <tablelayout android:id= "@+id/ Table2 "android:layout_width=" fill_parent "android:layout_height=" wrap_content "android:padding=" 1dip "> < tablerow> <button android:text= "0"/> <button android:text= "1"/> <button android:text= "2"/> < Button android:text= "+"/> <button android:text= "="/> </TableRow> <TableRow> <button android: text= "3"/> <button android:text= "4"/> <button android:text= "5"/> <button android:text= "-"/> < Button android:text= "*"/> </TableRow> <TableRow> <button android:text= "6"/> <button android:text= "7"/> <button android:text= "8"/> <button android:text= "9"/> <button android:text= "/"/> </TableRow> </ Tablelayout> </LinearLayout>
Introduction of Tablelayout
The Tablelayout class manages controls in rows and columns, with each behavior a TableRow object, or a view control.
When you are TableRow an object, you can add child controls under TableRow, and each child control occupies a column by default.
When you view, the view is exclusive to one row.
Determination of the number of rows and columns in Tablelayout
The number of rows in the tablelayout is specified directly by the developer, that is, how many TableRow objects (or view controls) there are.
The number of tablelayout columns equals the number of TableRow columns 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 column number is 4.
Three, the tablelayout can set the attribute detailed explanation
The properties that tablelayout can set include global properties and cell properties.
1, global properties are also column properties, with the following 3 parameters:
Android:stretchcolumns sets the columns that can be stretched. The column can be stretched in a row direction and can occupy up to one whole row.
Android:shrinkcolumns sets the columns that can be shrunk. The contents of the child control are displayed in the column direction when the contents of the control are too numerous to be filled with rows.
Android:collapsecolumns sets the columns to hide.
Example:
android:stretchcolumns= "0" No. 0 column can be stretched
android:shrinkcolumns= "1,2" 1th, 2 columns can be contracted
android:collapsecolumns= "*" hides all rows
Description: The column can have both Stretchcolumns and Shrinkcolumns properties, if this, then when the contents of the column n a long time, "multiline" display its contents. (This is not really a multiline, but the system automatically adjusts the layout_height of the line as needed)
2, cell properties, with the following 2 parameters:
Android:layout_column specifies that the cell appears in the first few columns
ANDROID:LAYOUT_SPAN Specifies the number of columns occupied by the cell (when unspecified, 1)
Example:
android:layout_column= "1" The control is displayed in column 1th
Android:layout_span= "2" This control occupies 2 columns
Description: A control can also have both of these features.
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/"
Android "android:orientation=" vertical "android:layout_width=" fill_parent "android:layout_height=" Fill_parent " android:padding= "3dip" > <!--1th tablelayout, which describes the column properties in the table. The No. 0 column can be stretched, the 1th column can be shrunk, the 2nd column is hidden--> <textview android:text= "Table 1: Global Settings: Column property Settings" android:layout_height= "Wrap_content" Android: Layout_width= "Wrap_content" android:textsize= "15sp" android:background= "#7f00ffff"/> <tablelayout
= "@+id/table1" android:layout_width= "fill_parent" android:layout_height= "wrap_content" android:stretchColumns= "0" android:shrinkcolumns= "1" android:collapsecolumns= "2" android:padding= "3dip" > <TableRow> <button android:text= "This column can be stretched"/> <button android:text= "This column can shrink"/> <button android:text= "I was hidden"/> </tablerow
> <TableRow> <textview android:text= "I'm stretching to the line, I can be Long"/> <textview android:text= "I'm shrinking in the column direction, I can be very deep"/> </TableRow> </tablelayout> <!--2nd Tablelayout, which describes the properties of cells in a table, including: Android:layout_column and Android:layout_span--> <textview Android : text= "Table 2: Cell settings: Specify cell property Settings" android:layout_height= "Wrap_content" android:layout_width= "Wrap_content" Android: Textsize= "15SP" android:background= "#7f00ffff"/> <tablelayout android:id= "@+id/table2" android:layout_width= "Fill_parent" android:layout_height= "wrap_content" android:padding= "3dip" > <TableRow> <button android: text= "No. 0 column"/> <button android:text= "1th column"/> <button android:text= "2nd column"/> </TableRow> <tablerow > <textview android:text= "I was designated in the 2nd column" android:layout_column= "2"/> </TableRow> <TableRow> < TextView android:text= "I cross 1 to 2 columns, do not believe you see!" "android:layout_column=" 1 "android:layout_span=" 2 "/> </TableRow> </TableLayout> <!--
3rd Tablelayout, using the Extensible feature layout--> <textview android:text= "Table 3: Application One, non-uniform layout" android:layout_height= "Wrap_content" Android:layout_width= "Wrap_content" android:textsize= "15SP" Android:background= "#7f00ffff"/> <tablelayout android:id= "@+id/table3" android:layout_width= "Fill_parent" android:layout _height= "Wrap_content" android:stretchcolumns= "*" android:padding= "3dip" > <TableRow> <button android: text= "One" ></Button> <button android:text= "Two words" ></Button> <button android:text= "three words" ></ Button> </TableRow> </TableLayout> <!--4th tablelayout, use the extensibility feature and specify the width of each control, such as 1dip--> <
TextView android:text= "Table 4: Application Two, uniform layout" android:layout_height= "wrap_content" android:layout_width= "Wrap_content" Android:textsize= "15SP" android:background= "#7f00ffff"/> <tablelayout android:id= "@+id/table4" Android:
Layout_width= "Fill_parent" android:layout_height= "wrap_content" android:stretchcolumns= "*" android:padding= "3dip" > <TableRow> <button android:text= "one" android:layout_width= "1dip" ></Button> <button android: text= "Two words" android:layout_width= "1dip" ></Button> <button android:text= "three words" Android:layoUt_width= "1dip" ></Button> </TableRow> </TableLayout> <textview android:text= "Table 5: Application Three, uniform layout" android:layout_height= "Wrap_content" android:layout_width= "wrap_content" android:textsize= "15sp" Android: background= "#7f00ffff"/> <tablelayout android:id= "@+id/table5" android:layout_width= "Fill_parent" Android: layout_height= "Wrap_content" android:stretchcolumns= "*" android:padding= "6dip" > <TableRow> <button android:text= "One" android:layout_width= "1dip" ></Button> <button android:text= "two words" android:layout_width= "1dip" ></Button> <button android:text= "three words" android:layout_width= "1dip" ></Button> <button android:text= "Four words" android:layout_width= "1dip" ></Button> <button style= "? android:attr/
Buttonstylesmall "android:layout_width=" 1dip "android:layout_height=" wrap_content "android:text=" New button " Android:id= "@+id/button"/> </TableRow> </TableLayout> </LinearLayout>
The above content is small force to introduce the Android tablelayout table layout, I hope to help!