Android table layout & lt; TableLayout & gt;

Source: Internet
Author: User
Tags xml attribute

Table layout is tableLayout. The table layout manages the UI component in the form of rows and columns. TablelLayout does not need to explicitly declare how many rows and columns are contained, but uses TableRow, and other components to control the number of rows and columns of a table,
TableRow is also a container. Therefore, you can add other components to TableRow. If no component is added, a column is added to the table.
If you want to add a component to TableLayout, the component occupies a row directly.
In table layout, the column width is determined by the widest cell in the column. The layout width of the entire table is determined by the width of the parent container (the parent container is filled by default ).
TableLayout inherits LinearLayout, so it fully supports all XML attributes supported by LinearLayout. In addition, TableLayout also supports the following attributes:
XML Attribute usage instructions
1. andriod: collapseColumns setColumnsCollapsed (int, boolean) sets the serial numbers of columns to be hidden, separated by commas
2. android: shrinkColumns setShrinkAllColumns (boolean) sets the serial number of the column to be shrunk. Multiple columns are separated by commas.
3. android: stretchColimns setSretchAllColumnds (boolean) sets the serial numbers of columns that can be stretched. Multiple columns are separated by commas (,).
 
The Code is as follows:
<? 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"
>
<! -- Define the layout of the first table, specify that the second column is allowed to contract, and the third column is allowed to stretch -->
<TableLayout
Android: id = "@ + id/tablelayout1"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: shrinkColumns = "1"
Android: stretchColumns = "2"
>
<! -- Directly add a button, which occupies a row. -->
<Button
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "button occupying one row"/>
<! -- First add a tableRow and add three buttons. The result is that the three buttons are arranged as one row in the tableRow (ROW). -->
<TableRow>
<Button android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "RBtn1"/>
<Button
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "RBtn2"/>
<Button
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "RBtn3"/>
</TableRow>
</TableLayout>
</LinearLayout>
The code above demonstrates the use of TableRow in tableLayour, the use of TableRow, and the use of TableRow, and the contraction allowed in the second column, and the third column can be stretched. The running result is as follows:
 
The following describes how to hide and use XML attributes. Add the code in TableLayout,
 
Android: collapseColumns = "0"
The Code is as follows:
 
Note: When setting the column number in the attribute, it is from 0, 1, 2, 3 ....
Not 1, 2, 3...

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.