Case study of TableLayout (table layout) + information list for Android Application Development

Source: Internet
Author: User

 

The layout style of a table is similar to that of a table in HTML, but the labels used are different.

□< TableLayout> is a top-level element and uses a table layout.

□< TableRow> define a row

□< TextView> define the content of a cell

The content of the main. xml layout file is as follows:

 

<? Xml version = "1.0" encoding = "UTF-8"?>

<TableLayout

Xmlns: android = "http://schemas.android.com/apk/res/android

Android: layout_width = "fill_parent"

Android: layout_height = "fill_parent"

Android: stretchColumns = "0, 1, 2, 3"

>

<TableRow>

<TextView

Android: text = "@ string/name"

Android: gravity = "center"

Android: padding = "3dip"/>

<TextView

Android: text = "@ string/gender"

Android: gravity = "center"

Android: padding = "3dip"/>

<TextView

Android: text = "@ string/age"

Android: gravity = "center"

Android: padding = "3dip"/>

<TextView

Android: text = "@ string/phonenum"

Android: gravity = "center"

Android: padding = "3dip"/>

</TableRow>

<TableRow>

<TextView

Android: text = "@ string/name1"

Android: gravity = "center"

Android: padding = "3dip"/>

<TextView

Android: text = "@ string/gender1"

Android: gravity = "center"

Android: padding = "3dip"/>

<TextView

Android: text = "@ string/age1"

Android: gravity = "center"

Android: padding = "3dip"/>

<TextView

Android: text = "@ string/phonenum1"

Android: gravity = "center"

Android: padding = "3dip"/>

</TableRow>

<TableRow>

<TextView

Android: text = "@ string/name2"

Android: gravity = "center"

Android: padding = "3dip"/>

<TextView

Android: text = "@ string/gender1"

Android: gravity = "center"

Android: padding = "3dip"/>

<TextView

Android: text = "@ string/age2"

Android: gravity = "center"

Android: padding = "3dip"/>

<TextView

Android: text = "@ string/phonenum2"

Android: gravity = "center"

Android: padding = "3dip"/>

</TableRow>

</TableLayout>

□Android: stretchColumns = "0, 1, 2, 3"

This attribute specifies that each row is filled with blank space by columns 0, 1, 2, and 3.

□Gravity specifies the text alignment mode, and the case is set to center alignment.

□Padding specifies the gap between the view and the view content, in pixels.

The content of the corresponding strings. xml file is as follows:

 

<? Xml version = "1.0" encoding = "UTF-8"?>

<Resources>

<String name = "name"> name </string>

<String name = "gender"> gender </string>

<String name = "age"> age </string>

<String name = "phonenum"> phone number </string>

<String name = "gender1"> male </string>

<String name = "gender2"> female </string>

<String name = "name1"> Michael </string>

<String name = "age1"> 25 </string>

<String name = "phonenum1"> 1234567 </string>

<String name = "name2"> Li Si </string>

<String name = "age2"> 24 </string>

<String name = "phonenum2"> 7654321 </string>

</Resources>

The interface effect is as follows:

 

Excerpted from the column

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.