Android Starter Series: UI components: Layout Manager: GridLayout

Source: Internet
Author: User

To write an example of a calculator, the layout file is as follows:

<? XML version= "1.0" encoding= "Utf-8" ?> <  xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:layout_gravity= "Center"Android:usedefaultmargins= "true"Android:columncount= "4"    >        <ButtonAndroid:text= "@string/zero"Android:background= "#DFDFDF"android:textsize= "30SP"Android:layout_columnspan= "4"android:gravity= "Center_vertical|right"Android:paddingright= "8DP"android:layout_gravity= "Fill"android:clickable= "false"        />        <ButtonAndroid:text= "@string/clear"Android:layout_columnspan= "3"android:layout_gravity= "Fill"        />    <ButtonAndroid:text= "@string/divide"android:layout_gravity= "Fill"        />    <ButtonAndroid:text= "@string/one"android:layout_gravity= "Fill"        />    <ButtonAndroid:text= "@string/two"android:layout_gravity= "Fill"        />    <ButtonAndroid:text= "@string/three"android:layout_gravity= "Fill"        />    <ButtonAndroid:text= "@string/multiply"android:layout_gravity= "Fill"        />    <ButtonAndroid:text= "@string/four"android:layout_gravity= "Fill"        />    <ButtonAndroid:text= "@string/five"android:layout_gravity= "Fill"        />    <ButtonAndroid:text= "@string/six"android:layout_gravity= "Fill"        />    <ButtonAndroid:text= "@string/sub"android:layout_gravity= "Fill"        />    <ButtonAndroid:text= "@string/seven"android:layout_gravity= "Fill"        />    <ButtonAndroid:text= "@string/eight"android:layout_gravity= "Fill"        />    <ButtonAndroid:text= "@string/nine"android:layout_gravity= "Fill"        />    <ButtonAndroid:text= "@string/add"Android:layout_rowspan= "3"android:layout_gravity= "Fill"        />    <ButtonAndroid:text= "@string/zero"Android:layout_columnspan= "2"android:layout_gravity= "Fill"        />    <ButtonAndroid:text= "@string/dot"android:layout_gravity= "Fill"        />                       <ButtonAndroid:text= "@string/equal"Android:layout_columnspan= "3"android:layout_gravity= "Fill"        />        </GridLayout>

Where the string file is Res/values/string.xml:

<?XML version= "1.0" encoding= "Utf-8"?><Resources>    <stringname= "App_name">My Second App</string>    <stringname= "Hello_world">Hello world!</string>    <stringname= "Action_settings">Settings</string>    <stringname= "Str_hello">Hello, Android!</string>    <stringname= "Calc_title">Calculator</string>    <stringname= "Zero">0</string>    <stringname= "One">1</string>    <stringname= "both">2</string>    <stringname= "three">3</string>    <stringname= "Four">4</string>    <stringname= "Five">5</string>    <stringname= "Six">6</string>    <stringname= "Seven">7</string>    <stringname= "Eight">8</string>    <stringname= "Nine">9</string>    <stringname= "dot">.</string>    <stringname= "Add">+</string>    <stringname= "Sub">-</string>    <stringname= "Multiply">*</string>    <stringname= "Divide">/</string>    <stringname= "equal">=</string>    <stringname= "Clear">C</string></Resources>

The result of the operation is:

The results shown in the last row (line 7th) and the last column (column 4th) are not imagined.

Android Starter Series: UI components: Layout Manager: GridLayout

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.