Android layout tablelayout Table layout _android

Source: Internet
Author: User

The Tablelayout class manages controls in rows and columns, with each behavior a TableRow object, or a view control. When you are TableRow an object, you can add child controls under TableRow, and each child control occupies a column by default. When you view, the view is exclusive to one row.

Three commonly used properties

Android:collapsecolumns: Sets the ordinal number of the column that needs to be hidden

Android:shrinkcolumns: Sets the column number of the column that is allowed to be shrunk

Android:stretchcolumns: Sets the column number of the column that is to run the extrusion

Learning Guide Map

(1) A brief introduction to Tablelayout

Java's swing programming and HTML are often used in tables, visible tables are used in application development, and Android also provides us with this layout.

(2) How to determine the number of rows

A: Directly to the tablelayout component, directly to the line

B: If you want to add more than one component on a single line, you need to use TableRow to add

How many components in the C:tablerow, how many columns will there be in this line

(3) Three common properties (all are counted from zero)

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;

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

Collapsed: If a column is set to collapsed, all cells of that column are hidden;

(4) Use instance (no component has an ID set for the demo 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" &
  Gt <!--defines the first table layout, specifies that the second column allows contraction, the third column stretches--> <tablelayout android:layout_width= "Match_parent" android:layout_height = "Wrap_content" android:shrinkcolumns= "1" android:stretchcolumns= "2" > <!--Adding a component directly will monopolize a row--> <but
      ton android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "one line Alone" /> <TableRow> <button android:layout_width= "wrap_content" android:layout_height= "Wra" P_content "android:text=" "normal button"/> <button android:layout_width= "Wrap_content" android:l
        ayout_height= "wrap_content" android:text= "shrink button"/> <button android:layout_width= "Wrap_content" Android:layout_height= "Wrap_content" android:text= "Stretch button"/> </TableRow> </TableLayout> <!--define the second table layout specifies that the second column is hidden-- > <tablelayout android:layout_width= "match_parent" android:layout_height= "Wrap_content" Android:collap secolumns= "1" > <!--adding components directly will monopolize one row--> <button android:layout_width= "Wrap_content" Android:lay out_height= "Wrap_content" android:text= "one line Alone"/> <TableRow> <button Android:lay
        Out_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_height= "Wrap_content" Android:te
    xt= "Normal button"/> </TableRow> </TableLayout> <!--defines the third table layout, specifies the second column, and the third column can be stretched--> <tablelayout Android:layout_width= "MAtch_parent "android:layout_height=" wrap_content android:stretchcolumns= "1,2" > <!--adding components directly will be exclusive to one line--> <button android:layout_width= "wrap_content" android:layout_height= "wrap_content" alone accounted for One line "/> <TableRow> <button android:layout_width=" Wrap_content "Android:layout_h
        eight= "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> </table Layout> </LinearLayout>

The above content is a small series to introduce the Android layout of the Tablelayout table layout, I hope you like.

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.