GridLayout use of Android development UI

Source: Internet
Author: User

1.GridLayout

Website

GridLayout contains the following properties :

Android:alignmentmode
Property Description: When the alignmargins is set, the outer bounds of the view are calibrated. You can take the following values:
Alignbounds--The subassembly view boundary.
Alignmargins--The subassembly view margin.

Android:columncount
Property Description: Maximum number of columns for GridLayout

Android:rowcount
Property Description: Maximum number of rows for GridLayout

Android:columnorderpreserved
Property Description: When set to True, the column bounds are displayed in the same order as the column index. The default is true.

Android:orientation
Property Description: GridLayout The layout direction of the neutron element. The following values are available:
Horizontal--Horizontal layout.
Vertical--Vertical layout.

Android:roworderpreserved
Property Description: When set to true, the row bounds are displayed in the same order as the row index. The default is true.

Android:usedefaultmargins
Property Description: When you set ture, when you do not specify a layout parameter for the view, tell GridLayout to use the default margin. The default value is False.

These are the properties of the GridLayout layout itself.

2 GridLayout child element properties

The properties of the GridLayout described above are properties of the GridLayout layout itself; GridLayout the attributes supported by the elements in the layout. GridLayout the attributes of an element in a layout, defined in gridlayout.layoutparams . The values are as follows:

2.1 Android:layout_column

Property Description : Displays the column for the space. For example, android:layout_column= "0", which indicates that the control is displayed in column 1th, android:layout_column= "1", indicating that the control is displayed in the 2nd column.

1<?xml version= "1.0" encoding= "Utf-8"?>2<gridlayout xmlns:android= "Http://schemas.android.com/apk/res/android"3Android:layout_width= "Wrap_content"4android:layout_height= "Wrap_content"5android:orientation= "Horizontal"6Android:rowcount= "2"7Android:columncount= "3" >8<Button9Android:id= "@+id/one"Tenandroid:layout_column= "1" Oneandroid:text= "1"/> A<Button -Android:id= "@+id/two" -android:layout_column= "0" theandroid:text= "2"/> -<Button -Android:id= "@+id/three" -android:text= "3"/> +<Button -Android:id= "@+id/devide" +android:text= "/"/>

the corresponding display :

Layout File Description :
android:orientation= "Horizontal"--the layout direction of controls in GridLayout is horizontal layout.
Android:rowcount= "2"--GridLayout the maximum number of rows is 2 rows.
Android:columncount= "3"--GridLayout the maximum number of columns is 3 columns.
android:layout_column= "1"--defines the control one in the 2nd column.
android:layout_column= "0"--defines the control in the 1th column.

2.2 Android:layout_columnspan

Property Description : The number of columns that the control occupies. For example, android:layout_columnspan= "2", which means that the control occupies 2 columns.

Layout File Example :

1<?xml version= "1.0" encoding= "Utf-8"?>2<gridlayout xmlns:android= "Http://schemas.android.com/apk/res/android"3Android:layout_width= "Wrap_content"4android:layout_height= "Wrap_content"5android:orientation= "Horizontal"6Android:rowcount= "2"7Android:columncount= "3" >8<Button9Android:id= "@+id/one"Tenandroid:layout_column= "0" OneAndroid:layout_columnspan= "2" Aandroid:text= "1"/> -<Button -Android:id= "@+id/two" theandroid:text= "2"/> -<Button -Android:id= "@+id/three" -android:text= "3"/> +<Button -Android:id= "@+id/devide" +android:text= "/"/> A  at</GridLayout>

the corresponding display :

Layout File Description :

The number "1" actually occupies a space of 2 columns, but the 2nd column appears blank. To make the 2nd column appear blank, you need to set the Android:layout_gravity property, as shown in the following example.

2.3 Android:layout_row

Property Description : The row in which the control is located. For example, android:layout_row= "0" means that the control is displayed on line 1th, and android:layout_row= "1" means that the control is displayed on line 2nd. It is similar to the android:layout_column.

2.4 Android:layout_rowspan

Property Description : The number of rows that the control occupies. For example, android:layout_rowspan= "2", which means that the control occupies 2 rows. It is similar to the Android:layout_columnspan.

2.5 android:layout_gravity

Property Description :

How the control is laid out. You can take the following values:
Top-controls are placed at the top of the container without changing the size of the control.
Bottom--controls are placed at the bottom of the container without changing the size of the control.
Left-the control is placed on the side of the container without changing the size of the control.
Right-the control is placed to the left of the container without changing the size of the control.
Center_vertical-The control is placed in the middle of the container in the vertical direction without changing the size of the control.
Fill_vertical--if desired, extends the control vertically.
Center_horizontal-controls are placed horizontally in the middle of the container without changing the size of the control.
Fill_horizontal--extends the control horizontally, if necessary.
Center-controls are placed in the middle of the container without changing the size of the control.
Fill-extends the control horizontally and vertically, if necessary.
Clip_vertical--vertical cut, the direction of clipping is based on the Top/bottom layout property of the control. If the gravity of the control is vertical: if its gravity is top, the bottom of the control is clipped, and if the control's gravity is bottom, the top of the control is clipped.
Clip_horizontal--Horizontal clipping, the direction of clipping is based on the Left/right layout properties of the control. If the gravity of the control is horizontal: If its gravity is left, the right side of the control is clipped, and if the control's gravity is true, then the control is clipped to the ieft.
Start-the control is placed at the beginning of the container and does not change the size of the control.
End-the control is placed at the end of the container and does not change the size of the control.


corresponding function : setgravity (int)

Layout File Example:

1<?xml version= "1.0" encoding= "Utf-8"?>2<gridlayout xmlns:android= "Http://schemas.android.com/apk/res/android"3Android:layout_width= "Wrap_content"4android:layout_height= "Wrap_content"5android:orientation= "Horizontal"6Android:rowcount= "2"7Android:columncount= "3" >8<Button9Android:id= "@+id/one"Tenandroid:layout_column= "0" OneAndroid:layout_columnspan= "2" Aandroid:layout_gravity= "Fill" -android:text= "1"/> -<Button theAndroid:id= "@+id/two" -android:text= "2"/> -<Button -Android:id= "@+id/three" +android:text= "3"/> -<Button +Android:id= "@+id/devide" Aandroid:text= "/"/> at  -</GridLayout>

the corresponding display :

3 Application Examples

Define a simple Calculator interface that contains "0-9 、.、 + 、-、 *,/, =,". Implemented with GridLayout.

Layout file

1<?xml version= "1.0" encoding= "Utf-8"?>2<!--gridlayout:5 row 4 column horizontal layout--3<gridlayout xmlns:android= "Http://schemas.android.com/apk/res/android"4Android:layout_width= "Wrap_content"5android:layout_height= "Wrap_content"6android:orientation= "Horizontal"7Android:rowcount= "5"8Android:columncount= "4" >9<ButtonTenAndroid:id= "@+id/one" Oneandroid:text= "1"/> A<Button -Android:id= "@+id/two" -android:text= "2"/> the<Button -Android:id= "@+id/three" -android:text= "3"/> -<Button +Android:id= "@+id/devide" -android:text= "/"/> +<Button AAndroid:id= "@+id/four" atandroid:text= "4"/> -<Button -Android:id= "@+id/five" -android:text= "5"/> -<Button -Android:id= "@+id/six" inandroid:text= "6"/> -<Button toAndroid:id= "@+id/multiply" +android:text= "x"/> -<Button theAndroid:id= "@+id/seven" *android:text= "7"/> $<ButtonPanax NotoginsengAndroid:id= "@+id/eight" -android:text= "8"/> the<Button +Android:id= "@+id/nine" Aandroid:text= "9"/> the<Button +Android:id= "@+id/minus" -android:text= "-"/> $<Button $Android:id= "@+id/zero" -Android:layout_columnspan= "2" -android:layout_gravity= "Fill" theandroid:text= "0"/> -<ButtonWuyiAndroid:id= "@+id/point" theAndroid:text= "." /> -<Button WuAndroid:id= "@+id/plus" -Android:layout_rowspan= "2" Aboutandroid:layout_gravity= "Fill" $android:text= "+"/> -<Button -Android:id= "@+id/equal" -Android:layout_columnspan= "3" Aandroid:layout_gravity= "Fill" +android:text= "="/> the</GridLayout>

Transferred from: http://www.cnblogs.com/skywang12345/p/3154150.html

GridLayout use of Android development UI

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.