Android Notes (10) layout in Android-Grid layout

Source: Internet
Author: User

The grid layout is a new layout manager for Android4.0, so it needs to be available after Android4.0, and the previous platform will need to be imported into the appropriate support library.

The GridLayout function is similar to the table tag in HTML, which divides the entire container into row*column meshes, each of which can place a component, or set how many columns and rows a component spans.

GridLayout provides the setrowcount (int) and setcolumncount (int) methods to control the number of rows and columns of the grid.

Simple code example:

Gridlayout.xml

<?XML version= "1.0" encoding= "Utf-8"?><GridLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:rowcount= "6"Android:columncount= "4"Android:id= "@+id/root">    <!--set a text box that spans four columns and sets the foreground color, background color, and other properties of the text box -    <TextViewAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_columnspan= "4"android:textsize= "50SP"Android:layout_marginleft= "4px"Android:layout_marginright= "4px"android:padding= "5px"android:layout_gravity= "Right"Android:background= "#eee"Android:textcolor= "#000"Android:text= "0"        />    <!--Define a button that spans four columns -    <ButtonAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_columnspan= "4"Android:text= "Clear"/>    <!--Add another button -    <ButtonAndroid:text= "7"Android:layout_rowweight= "1"Android:layout_columnweight= "1"/>    <ButtonAndroid:text= "8"Android:layout_rowweight= "1"Android:layout_columnweight= "1"/>    <ButtonAndroid:text= "9"Android:layout_rowweight= "1"Android:layout_columnweight= "1"/>    <ButtonAndroid:text="/"Android:layout_rowweight= "1"Android:layout_columnweight= "1"/>    <ButtonAndroid:text= "4"Android:layout_rowweight= "1"Android:layout_columnweight= "1"/>    <ButtonAndroid:text= "5"Android:layout_rowweight= "1"Android:layout_columnweight= "1"/>    <ButtonAndroid:text= "6"Android:layout_rowweight= "1"Android:layout_columnweight= "1"/>    <ButtonAndroid:text="*"Android:layout_rowweight= "1"Android:layout_columnweight= "1"/>    <ButtonAndroid:text= "1"Android:layout_rowweight= "1"Android:layout_columnweight= "1"/>    <ButtonAndroid:text= "2"Android:layout_rowweight= "1"Android:layout_columnweight= "1"/>    <ButtonAndroid:text= "3"Android:layout_rowweight= "1"Android:layout_columnweight= "1"/>    <ButtonAndroid:text="-"Android:layout_rowweight= "1"Android:layout_columnweight= "1"/>    <ButtonAndroid:text= "0"Android:layout_rowweight= "1"Android:layout_columnweight= "1"/>    <ButtonAndroid:text="."Android:layout_rowweight= "1"Android:layout_columnweight= "1"/>    <ButtonAndroid:text="+"Android:layout_rowweight= "1"Android:layout_columnweight= "1"/>    <ButtonAndroid:text="="Android:layout_rowweight= "1"Android:layout_columnweight= "1"/></GridLayout>

Operation Result:

Android Notes (10) layout in Android-Grid layout

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.