Android Layout Manager (table layout)

Source: Internet
Author: User

Table layout is represented by Tablelayout, Tablelayout inherited LinearLayout, so his essence is still linearlayout.

Table layouts are managed in rows and columns, where you don't need to declare how many rows and columns to use, but instead add tablerow and other components to control the number of rows and columns in the table.

Each time you add a TableRow to Tablelayout, the TableRow is a table row, and TableRow is also a container where you can add additional components continuously, adding a column to each of the table's columns.

In the table layout manager, you can set the following three ways to behave for cells

    1. Shrinkable: If a column is set to Shrinkable, the width of all cells in the column can be shrunk to ensure that the table fits the width of the parent container
    2. Stretchable: If a column is set to Stretchable, then the width of all the cells in the column can be stretched to ensure that the component fills the table free control
    3. Collapsed: If a column is set to this property, all cells of that column will be hidden

Because Tablelayout inherits the LinearLayout class, the following three properties are supported in addition to all properties that support LinearLayout

XML Properties




setcolumncollapsed (Int,boolean)

Sets the ordinal of the column that needs to be hidden, and multiple uses are separated by commas


Setshrinkallcolumns (Boolean)

Sets the number of columns that are allowed to be shrunk, with multiple separated by commas


Setstretchallcolumns (Boolean)

Sets the number of columns allowed to be stretched, separated by commas

<linearlayout xmlns:android= "" xmlns:tools= "http// "android:layout_width=" fill_parent "android:layout_height=" Fill_parent "Android:orienta tion= "vertical" tools:context= "com.example.tablelayout.MainActivity" > <!--first tablelayout, specifying two columns allowed to shrink, three columns allowed to stretch --<tablelayout android:id= "@+id/tablelayout_one" android:layout_width= "Fill_parent" Andro id:layout_height= "Wrap_content" android:shrinkcolumns= "1" android:stretchcolumns= "3" > < Button android:id= "@+id/ok1" android:layout_width= "Wrap_content" android:layout_height= " Wrap_content "android:text=" button on a single line "/> <TableRow> <button Android                : id= "@+id/ok2" android:layout_width= "wrap_content" android:layout_height= "Wrap_content"            android:text= "Normal button"/><button android:id= "@+id/ok3" android:layout_width= "Wrap_content" Android : layout_height= "wrap_content" android:text= "shrink button"/> <button android:id= "@+                Id/ok4 "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "    android:text= "Stretch button"/> </TableRow> </TableLayout> <!--second Tablelayout, specify two columns to be hidden-- <tablelayout android:id= "@+id/tablelayout_two" android:layout_width= "Fill_parent" Android:layo ut_height= "Wrap_content" android:collapsecolumns= "2" > <button android:id= "@+id/ok5 "Android:layout_width=" wrap_content "android:layout_height=" Wrap_content "android:text=" Button "/> <TableRow> <button android:id=" @+id/ok6 "android:l Ayout_width= "Wrap_contenT "android:layout_height=" wrap_content "android:text=" normal button "/> <button Android:id= "@+id/ok7" android:layout_width= "Wrap_content" android:layout_height= "                Wrap_content "android:text=" shrink button "/> <button android:id=" @+id/ok8 " Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" Android:text = "Hide Button"/> </TableRow> </TableLayout> <!--third Tablelayout, specify two columns to allow stretching, three columns allow stretching--&lt ; Tablelayout android:id= "@+id/tablelayout_three" android:layout_width= "Fill_parent" android:layout_he            ight= "Wrap_content" android:shrinkcolumns= "All" > <button android:id= "@+id/ok9" Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:text= "Alone Button "/> <tablerow> <button android:id= "@+id/ok10" android:layout_width= "Wrap_content"                 android:layout_height= "Wrap_content" android:text= "normal button"/> <button Android:id= "@+id/ok11" android:layout_width= "wrap_content" android:layout_height= "WR                Ap_content "android:text=" Stretch button "/> <button android:id=" @+id/ok12 " Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:text= "Stretch button"/> </TableRow> </TableLayout></LinearLayout>

Android Layout Manager (table layout)

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: 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.