Android: tablelayout table layout details

Source: Internet
Author: User

This blog includes the following content:

1. Introduction to tablelayout

2,Determine the number of tablelayout Columns

3,Details about configurable attributes of tablelayout

4. An Instance with four tablelayout la S and

 

1. tablelayout the tablelayout class manages controls in the form of rows and columns. Each row is a tablerow object or a view control. When it is a tablerow object, you can add child controls under tablerow. By default, each child control occupies one column. When the value is a view, this view excludes one row. Ii. Determination of the number of tablelayout Columns

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.

Iii. Details about configurable attributes of tablelayout

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.

 

4. An Instance with four tablelayout la S and
1 <? XML version = "1.0" encoding = "UTF-8"?> 2 <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" 3 Android: Orientation = "vertical" 4 Android: layout_width = "fill_parent" 5 Android: layout_height = "fill_parent" 6 Android: padding = "3dip" 7> 8 9 <! -- 1st tablelayout, used to describe the column attributes in the table. 0th columns can be stretched, 1st columns can be shrunk, and 2nd columns are hidden --> 10 <textview 11 Android: text = "Table 1: global settings: column attribute settings" 12 Android: layout_height = "wrap_content" 13 Android: layout_width = "wrap_content" 14 Android: textsize = "15sp" 15 Android: Background = "# 7f00ffff"/> 16 <tablelayout 17 Android: id = "@ + ID/Table1" 18 Android: layout_width = "fill_parent" 19 Android: layout_height = "wrap_content" 20 Android: stretchcolumns = "0" 21 Android: shrinkcolumns = "1" 22 androi D: collapsecolumns = "2" 23 Android: padding = "3dip"> 24 <tablerow> 25 <button Android: text = "This column can be stretched"/> 26 <button Android: TEXT = "This column can be shrunk"/> 27 <button Android: text = "I am hidden"/> 28 </tablerow> 29 30 <tablerow> 31 <textview Android: TEXT = "I can stretch in the row direction, I can be very long"/> 32 <textview Android: text = "I shrink in the column direction, I can go deep "/> 33 </tablerow> 34 35 </tablelayout> 36 37 <! -- 2nd tablelayout, used to describe the attributes of cells in the table, including: Android: layout_column and Android: layout_span --> 38 <textview 39 Android: text = "Table 2: cell settings: specify the Cell Property Settings "40 Android: layout_height =" wrap_content "41 Android: layout_width =" wrap_content "42 Android: textsize =" 15sp "43 Android: background = "# 7f00ffff"/> 44 <tablelayout 45 Android: Id = "@ + ID/Table2" 46 Android: layout_width = "fill_parent" 47 Android: layout_height = "wrap_content" 48 android Oid: padding = "3dip"> 49 <tablerow> 50 <button Android: text = "0th columns"/> 51 <button Android: TEXT = "1st columns"/> 52 <button Android: text = "2nd columns"/> 53 </tablerow> 54 55 <tablerow> 56 <textview Android: TEXT = "I was specified in the 1st column" Android: layout_column = "1"/> 57 </tablerow> 58 59 <tablerow> 60 <textview 61 Android: TEXT = "I span 1 to 2 columns. Do not believe it! "62 Android: layout_column =" 1 "63 Android: layout_span =" 2 "64/> 65 </tablerow> 66 67 </tablelayout> 68 69 <! -- 3rd tablelayout, la --> 70 <textview 71 Android: text = "Table 3: Application 1, uneven layout" 72 Android: layout_height = "wrap_content" 73 Android: layout_width = "wrap_content" 74 Android: textsize = "15sp" 75 Android: Background = "# 7f00ffff"/> 76 <tablelayout 77 Android: id = "@ + ID/table3" 78 Android: layout_width = "fill_parent" 79 Android: layout_height = "wrap_content" 80 Android: stretchcolumns = "*" 81 Android: padding = "3dip" 82> 8 3 <tablerow> 84 <button Android: text = "1"> </button> 85 <button Android: text = ""> </button> 86 <button Android: TEXT = "three words"> </button> 87 </tablerow> 88 </tablelayout> 89 90 <! -- Use the 4th tablelayout feature and specify that the width of each control is the same, for example, 1dip --> 91 <textview 92 Android: text = "Table 4: Application 2, uniform layout "93 Android: layout_height =" wrap_content "94 Android: layout_width =" wrap_content "95 Android: textsize =" 15sp "96 Android: background = "# 7f00ffff"/> 97 <tablelayout 98 Android: Id = "@ + ID/table4" 99 Android: layout_width = "fill_parent" 100 Android: layout_height = "wrap_content" 101 Android: stretchcolumns = "*" 102 Android: padding = "3dip" 103> 104 <tablerow> 105 <button Android: text = "1" Android: layout_width = "1dip"> </button> 106 <button Android: text = "" Android: layout_width = "1dip"> </button> 107 <button Android: TEXT = "Three-character" Android: layout_width = "1dip"> </button> 108 </tablerow> 109 </tablelayout> 110 </linearlayout>

Note: The uniform layout of the 4th tablelayout tables has limited results. Its limitations are reflected in that when the row has n columns, the control content of each column cannot exceed 1/N.

Run: (1)


Figure 1 tablelayout running result

 

Bibliography:

[1] basic Android tutorial, translated by [us] Ed Burnette, Zhang Bo, Gao chaoqin, and Yang Yue, Beijing: People's post and telecommunications press, 2009.11

[2] Android development tutorial, translated by [us] Mark L. Murphy, translated by Li xuefei and Wu minghui, Beijing: People's post and telecommunications press, 2010.12

[3] explanation of Android core technologies and instances, Wu Yafeng, suo yina, Beijing: Electronics Industry Press, 2010.10

Turn: http://blog.sina.com.cn/s/blog_63c66eb60100u29p.html

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.