Detailed description of tablelayout table layout

Source: Internet
Author: User

1. Introduction to tablelayout

2,Determine the number of tablelayout Columns

3,Details about configurable attributes of tablelayout

4. An Instance with four tablelayout la S and

 

1. tablelayout the tablelayout class manages controls in the form of rows and columns. Each row is a tablerow object or a view control. When it is a tablerow object, you can add child controls under tablerow. By default, each child control occupies one column. When the value is a view, this view excludes one row. Ii. Determination of the number of tablelayout Columns

The number of rows of tablelayout is directly specified by the developer, that is, the number of tablerow objects (or view controls.

The number of columns in tablelayout is equal to the number of columns in tablerow with the maximum number of child controls. For example, if the first tablerow contains two sub-controls, the second tablerow contains three, and the third tablerow contains four, the number of columns of the tablelayout is 4.

Iii. Details about configurable attributes of tablelayout

Attributes that can be set for tablelayout include global attributes and cell attributes.

1. Global attributes, that is, column attributes, have the following three parameters:

Android: stretchcolumns. This column can be stretched to the row direction, and can occupy a maximum of one whole row.

Android: shrinkcolumns. When the sub-control of this column contains too much content and is already packed with rows, the content of this Sub-control will be displayed in the column direction.

Android: collapsecolumns: Set the columns to be hidden.

Example:

Android: stretchcolumns = "0" 0th columns stretch

Android: shrinkcolumns = "1, 2" column 1 and column 2 can be reduced

Android: collapsecolumns = "*" hide all rows

Note: columns can have the attributes stretchcolumns and shrinkcolumns at the same time. If so, when there are more than n columns in the column, "multiple rows" will be displayed. (This is not a real multi-row, but the layout_height of the row is automatically adjusted as needed)

2. The cell attribute has the following two parameters:

Android: layout_column specifies the column in which the cell is displayed.

Android: layout_span specifies the number of columns occupied by the Cell (1 if not specified)

Example:

Android: layout_column = "1" the control is displayed in the 1st Column

Android: layout_span = "2" this control occupies two columns

Note: A control can also have these two features.

 

4. An Instance with four tablelayout la S and

 

<? 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"
>

 <! -- 1st tablelayout, used to describe the column attributes in the table. 0th columns can be stretched, 1st columns can be shrunk, and 2nd columns are hidden -->
<Textview
Android: text = "Table 1: global settings: column attribute settings"
Android: layout_height = "wrap_content"
Android: layout_width = "wrap_content"
Android: textsize = "15sp"
Android: Background = "# 7f00ffff"/>
<Tablelayout
Android: Id = "@ + 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 be shrunk"/>
<Button Android: text = "I am hidden"/>
</Tablerow>

<Tablerow>
<Textview Android: text = "I am stretching towards the line, I can be very long"/>
<Textview Android: text = ", I can very deep"/>
</Tablerow>

</Tablelayout>
 
<! -- 2nd tablelayout, used to describe the attributes of cells in the 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 = "column 0th"/>
<Button Android: text = "column 1st"/>
<Button Android: text = "Column 2nd"/>
</Tablerow>

<Tablerow>
<Textview Android: text = "I was specified in Column 1st" Android: layout_column = "1"/>
</Tablerow>

<Tablerow>
<Textview
Android: text = "I span 1 to 2 columns. Do not believe it! "
Android: layout_column = "1"
Android: layout_span = "2"
/>
</Tablerow>

</Tablelayout>
 
<! -- 3rd tablelayout and use the Extensible layout -->
<Textview
Android: text = "Table 3: Application 1, uneven 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 = "1"> </button>
<Button Android: text = ""> </button>
<Button Android: text = "three words"> </button>
</Tablerow>
</Tablelayout>
 
<! -- 4th tablelayout, use the Extensible feature, and specify the same width for each control, such as 1dip -->
<Textview
Android: text = "Table 4: Application 2, even 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 = "1" Android: layout_width = "1dip"> </button>
<Button Android: text = "" Android: layout_width = "1dip"> </button>
<Button Android: text = "three words" Android: layout_width = "1dip"> </button>
</Tablerow>
</Tablelayout>
</Linearlayout>

Note: The uniform layout of the 4th tablelayout tables has limited results. Its limitations are reflected in that when the row has n columns, the control content of each column cannot exceed 1/N.

Run: (1)


Figure 1 tablelayout running result

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.