Android GridLayout Introduction, take calculator as an example

Source: Internet
Author: User



Introduction to Android GridLayout, Calculator for example

Android GridLayout Default horizontal layout element from left to right. You can control whether the orientation of the child element layout is horizontal or vertical by setting the property: Android:orientation=.

The GridLayout properties Android:layout_row and Android:layout_column set constant values to specify the number of rows that the GridLayout displays.

Set the Android:layout_rowspan or Android:layout_columnspan constant value, and set the android:layout_gravity= "fill" at the same time, the element will occupy the specified column across the boundary.

As an example of a simple calculator layout, this calculator can be implemented with just one layout file, the following is a calculator implemented using the Android GridLayout layout as follows:


The complete code for the Calculator XML layout file implemented with Android GridLayout:

<?xml version= "1.0" encoding= "Utf-8"? ><gridlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Wrap_content "android:layout_height=" Wrap_content "android:columncount=" 4 "Android oid:orientation= "Horizontal" android:rowcount= "5" > <button android:id= "@+id/one" android:text= " 1 "/> <button android:id=" @+id/two "android:text=" 2 "/> <button android:id=" @+id/th Ree "android:text=" 3 "/> <button android:id=" @+id/devide "android:text="/"/> <butt On android:id= "@+id/four" android:text= "4"/> <button android:id= "@+id/five" Android: text= "5"/> <button android:id= "@+id/six" android:text= "6"/> <button android:id= "@    +id/multiply "android:text=" x "/> <button android:id=" @+id/seven "android:text=" 7 "/> <button android:id= "@+id/eiGht "android:text=" 8 "/> <button android:id=" @+id/nine "android:text=" 9 "/> <button Android:id= "@+id/minus" android:text= "-"/> <button android:id= "@+id/zero" android:l Ayout_columnspan= "2" android:layout_gravity= "fill" android:text= "0"/> <button android:id= "@        +id/point "android:text=". "/> <button android:id=" @+id/plus "android:layout_gravity=" Fill " Android:layout_rowspan= "2" android:text= "+"/> <button android:id= "@+id/equal" Androi D:layout_columnspan= "3" android:layout_gravity= "fill" android:text= "="/></gridlayout>

Android GridLayout Introduction, take calculator as an example

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.