Android Layout _ table layout Tablelayout

Source: Internet
Author: User

I. Overview of Tablelayout

 The Tablelayout table layout model manages child controls in the form of rows and columns, each of which behaves as a TableRow object, or it can be a view object

Second, the global properties of Tablelayout

  1, Android:collapsecolumns = "Up"

Hides the indexed column starting from 0, and the column must be ongoing comma separated: 1,2,5

<Tablelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:collapsecolumns= "0" >    <TableRowAndroid:id= "@+id/tablerow1"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent">        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "First button"Android:id= "@+id/button" />        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "second Button"Android:id= "@+id/button2" />        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "third button"Android:id= "@+id/button3" />    </TableRow></Tablelayout>

  2, Android:shrikcolumns = "Up"

Shrinks the index column starting at 0. When a Lietaikuan (too much content) is not squeezed out of the screen, the column must be separated by commas: 1,2,5, you can use "*" instead of shrinking all the columns. Note that a column can represent both contraction and stretching.

<Tablelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:shrinkcolumns= "2" >    <TableRowAndroid:id= "@+id/tablerow1"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent">        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "First button"Android:id= "@+id/button" />        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "second Button"Android:id= "@+id/button2" />        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "The third button big God is on holiday." The point at the intersection of Caesar's Liberation card phone KARASGA "Android:id= "@+id/button3" />    </TableRow></Tablelayout>

  3, Android:stretchcolumns = "Up"

Stretches the index column starting at 0. To fill the rest of the remaining blank controls, the columns must be separated by commas: "*" instead of shrinking all columns. Note that a column can represent both contraction and stretching.

<Tablelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:stretchcolumns= "2" >    <TableRowAndroid:id= "@+id/tablerow1"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent">        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "First button"Android:id= "@+id/button" />        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "second Button"Android:id= "@+id/button2" />        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "third button"Android:id= "@+id/button3" />    </TableRow></Tablelayout>

Tablelayout Local properties (all properties of internal controls)

  1. android:layout_column = "1" The control is displayed in the second column

2, Android:layout_span = "2" The control occupies 2 columns

Iv. implement a simple calculator layout

<Tablelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:stretchcolumns="*"Android:shrinkcolumns="*">    <TextViewandroid:gravity= "Right|center"Android:layout_width= "Fill_parent"Android:layout_height= "Max"Android:text= "All"Android:id= "@+id/textview" />    <TableRowAndroid:id= "@+id/tablerow1"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent">        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "7"Android:id= "@+id/button" />        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "8"Android:id= "@+id/button2" />        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "9"Android:id= "@+id/button3" />        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text="/"Android:id= "@+id/button4" />    </TableRow>    <TableRowAndroid:id= "@+id/tablerow2"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent">        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "4"Android:id= "@+id/button5" />        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "6"Android:id= "@+id/button6" />        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "7"Android:id= "@+id/button7" />        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text="*"Android:id= "@+id/button8" />    </TableRow></Tablelayout>

  

Android Layout _ table layout Tablelayout

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.