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