Android layout ----- TableLayout (table layout) and tablelayout

Source: Internet
Author: User

Android layout ----- TableLayout (table layout) and tablelayout

Learning Map

 

(1) Introduction to TableLayout

Tables are often used in swing programming and html in java. It can be seen that many tables are used in application development. Similarly, android also provides us with such a layout method.

(2) how to determine the number of rows

A: directly to the TableLayout component and directly occupies a row

B: If you want to add multiple components in one row, you must use TableRow to add

C: The number of components in TableRow and the number of columns in this row

(3) three common attributes (all count from scratch)

Shrinkable: If a column is set to Shrinkable, the width of all cells in the column can be reduced to ensure that the table can adapt to the width of the parent container;

Stretchable: If a column is set to Stretchable, the width of all cells in the column can be stretched to ensure that the components fully fill the free space of the table;

Collapsed: If a column is set to Collapsed, all cells in the column will be hidden;

(4) use instances (no id is set for all components to demonstrate the effect)

<? Xml version = "1.0" encoding = "UTF-8"?> <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: layout_width = "match_parent" android: layout_height = "match_parent" android: orientation = "vertical"> <! -- Define the layout of the first table, specify that the second column can be reduced, and the third column can be stretched --> <TableLayout android: layout_width = "match_parent" android: layout_height = "wrap_content" android: shrinkColumns = "1" android: stretchColumns = "2"> <! -- Directly adding a component exclusive to a row --> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "occupying a single row"/> <TableRow> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "normal Button"/> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = ""/> <Button android: layout_width = "wrap_content" android: layout_he Ight = "wrap_content" android: text = "stretch button"/> </TableRow> </TableLayout> <! -- Define the second table layout and specify the second column to hide --> <TableLayout android: layout_width = "match_parent" android: layout_height = "wrap_content" android: collapseColumns = "1"> <! -- Directly adding a component exclusive to a row --> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "occupying a single row"/> <TableRow> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "normal Button"/> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "normal Button"/> <Button android: layout_width = "wrap_content" android: layout_he Ight = "wrap_content" android: text = "normal button"/> </TableRow> </TableLayout> <! -- Define the layout of the third table, specify the second column, and stretch the third column --> <TableLayout android: layout_width = "match_parent" android: layout_height = "wrap_content" android: stretchColumns = "1, 2"> <! -- Directly adding a component exclusive to a row --> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "occupying a single row"/> <TableRow> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "normal Button"/> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "stretch Button"/> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "stretch button"/> </TableRow> </TableLayout> </LinearLayout>

 

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.