Android:tablelayout Table Layout Detailed

Source: Internet
Author: User

Original: http://blog.sina.com.cn/s/blog_63c66eb60100u29p.html

What this blog post includes:

1, Tablelayout Introduction

2. determination of the number of tablelayout rows

3. Tablelayout properties can be set in a detailed

4. An example containing 4 tablelayout layouts and

Tablelayout Introduction The Tablelayout class manages controls in the form of rows and columns, each of which behaves as a TableRow object, or a view control.         When you are a TableRow object, you can add child controls under TableRow, and each child control occupies one column by default. When it is a view, the view is exclusive to one row. Determination of the number of tablelayout in the two-row

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.

Three, Tablelayout can set the properties of the detailed

Tablelayout properties that can be set include global properties and cell properties.

1, the global attribute is also the column property, has the following 3 parameters:

Android:stretchcolumns sets the columns that can be stretched. The column can stretch to the row direction, up to a full row.

Android:shrinkcolumns sets the columns 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 extendable

Android:shrinkcolumns= 1th, 2 columns can be shrunk

android:collapsecolumns= "*" hides all rows

Note: Columns can have both the Stretchcolumns and Shrinkcolumns properties, so if the column has more than N, "multiline" displays its contents. (This is not really multiple lines, but the system automatically adjusts the line's layout_height as needed)

2, cell properties, with 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.

四、一个 contains an example of 4 tablelayout layouts 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"
>

<!--1th Tablelayout, which is used to describe column properties in a table. The No. 0 column can be stretched, the 1th column can be shrunk, and 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
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= "The column can be stretched"/>
<button android:text= "This column can be shrunk"/>
<button android:text= "I was hidden"/>
</TableRow>

<TableRow>
<textview android:text= "I stretch in the direction of the line, I can be very long"/>
<textview android:text= "I shrink in the same 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 assigned in 1th column" android:layout_column= "1"/>
</TableRow>

<TableRow>
<textview
Android:text= "I cross 1 to 2 columns, don't believe you look! "
android:layout_column= "1"
Android:layout_span= "2"
/>
</TableRow>

</TableLayout>

<!--3rd tablelayout, layout with extendable features--
<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, using the extendable feature, and specifying a uniform width for 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 characters" android:layout_width= "1dip" ></Button>
</TableRow>
</TableLayout>
</LinearLayout>

Description: The uniform effect of the uniform layout in the 4th Tablelayout is limited. Its finite body now, when the row has N columns, the control content of each column cannot be more than 1/n.

Run: (1)

Figure 1 Tablelayout Run result diagram

Bibliography:

[1] Android Basics tutorial, []ed Burnette, Zhang Bo, Gao Chaoqin, Yang months, Beijing: People's post and telecommunications press, 2009.11

[2] Android Development starter Tutorial, [Mei]mark L. Murphy, Li Shefei, Wu Minghui, Beijing: People's post and telecommunications press, 2010.12

[3] "Android Core technology and examples", Wuya, Soina, Beijing: Electronics Industry Press, 2010.10

Reference article:

Android uses tablelayout layout stretch width

Android:tablelayout Table Layout Detailed

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.