Android table layout: Android: collapsecolumns, Android: shrinkcolumns and stretchcolumn

Source: Internet
Author: User

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.



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.




Tablelayout is a complex layout. The simplest method is to drag the control to make an interface. However, tablelayout is often used in the Code, for example, to make a table. This topic describes how to use 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" -------> In The 0th action order, try to fill the specified column with the blank part

If stretchcolumns is set to 0, the result is as follows: 0th columns should be filled as much as possible.

If stretchcolumns is set to 1, the result is as follows: 1st columns should be filled as much as possible.


2 Android: shrinkcolumns = "specified column": automatically extends the specified column to fill the available part in The 0th action order.

Shrinkcolumns does not work when the controls in layoutrow are not full of layoutrow layout, as shown in figure

When the controls in layoutrow are not full (rewrite the content of the third button)

3 Android: collapsecolumns = "specified column" 0th action order, hide the specified column>

Android: collapsecolumns when this attribute is null, for example:

Android: collapsecolumns = "0" means to remove the 0th columns, for example:

Related Article

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.