New UI-layout-GridLayout (grid layout) details, ui-gridlayout

Source: Internet
Author: User

New UI-layout-GridLayout (grid layout) details, ui-gridlayout

New UI-layout-GridLayout (grid layout)

-- Reprinted please indicate the source: coder-pig. You are welcome to repost it. Please do not use it for commercial purposes!


The piggy Android development and exchange group has been established. You are welcome to join us. You can be a newbie, cainiao, or a great god.

After all, the power is limited. There will certainly be a lot of flaws in writing. You are welcome to point out, brainstorm, And let pig's blog post.

For more details, help more people, O (∩ _ ∩) O thank you!

Piggy Android Development Exchange Group: Piggy Android Development Exchange Group No.: 421858269

New Android UI instance Daquan Directory: http://blog.csdn.net/coder_pig/article/details/42145907


This section introduces:

The layout to be introduced today is a new layout introduced after Android 4.0, and the TableLayout (table layout)

It is a bit similar, but he has a lot of things that the former does not have, and it is also better to use,

1) You can arrange components in the layout by yourself.

2) You can customize the number of rows and columns in the grid layout.

3) You can directly set the component to be located in a column of a row.

4) You can set the number of rows or columns that the component spans.

In addition to the above content, this section also provides you with gridLayout Problems and Solutions to lower version

How does the sdk use GridLayout! Next, let's start this course!



1) related property diagram:




2) use instances: Implementation of the calculator layout:

:


Implementation Code:

<GridLayout xmlns: android = "http://schemas.android.com/apk/res/android" xmlns: tools = "http://schemas.android.com/tools" android: id = "@ + id/GridLayout1" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: rowCount = "6" android: columnCount = "4" android: orientation = "horizontal"> <TextView android: background = "# FFCCCC" android: layout_gravity = "fill" android: layout_columnSpan = "4" android: text = "0" android: textSize = "50sp" android: layout_marginLeft = "5dp" android: layout_marginRight = "5dp"/> <Button android: text = "" android: layout_columnSpan = "2" android: layout_gravity = "fill"/> <Button android: text = "clear" android: layout_columnSpan = "2" android: layout_gravity = "fill"/> <Button android: text = "+"/> <Button android: text = "1"/> <Button android: text = "2"/> <Button android: text = "3"/> <Button android: text = "-"/> <Button android: text = "4"/> <Button android: text = "5"/> <Button android: text = "6"/> <Button android: text = "*"/> <Button android: text = "7"/> <Button android: text = "8"/> <Button android: text = "9"/> <Button android: text = "/"/> <Button android: layout_width = "wrap_content" android: text = ". "/> <Button android: text =" 0 "/> <Button android: text =" = "/> </GridLayout>


Code parsing:

The code is very simple, but the rollback and clear buttons span two columns, while others are directly added. By default, each component is

Take one row and one column. Pay attention to the following points:

We set the component span through android: layout_rowSpan and android: layout_columnSpan.

If you want to fill the component with rows or columns that have been crossed, you need to add the following attributes:

Android: layout_gravity = "fill "!!! It's like the computer's display of numbers!



3) usage:

① GridLayout divides the layout into rows, columns, and cells using virtual fine lines. It also supports the staggered arrangement of rows and columns.

② Procedure:

Step 1: first define the method of the component android: orientation horizontal or vertical, set how many rows and how many columns

Step 2: Set the row or column where the component is located. Remember to calculate it from 0. If this parameter is not set, each component occupies one column in one row by default.

Step 3: set the number of rows or columns that the component spans. After setting, you need to set a fill: android: layout_gravity = "fill"



4) Note the following when using GridLayout:

Because GirdLayout was launched only after 4.0, The minSDK version should be changed to 14 or later,

Otherwise, when writing the layout code, this stuff will be inexplicably wrong, saying that the GridLayout cannot be found,

Of course, if you want to be compatible with a lower version, you should read the following content!



5) How to Use GridLayout in earlier sdk versions:

The solution is simple: you only need to import the gridlayout package of the v7 package!

The v7 package is generally under the sdk: sdk \ extras \ android \ support \ v7 \ gridlayout directory

If you do not have one, you can download it here:

Gridlayout_v7_jay package download: http://pan.baidu.com/s/1kTC2s3l


Next, complete the import package according to the following process:


FindSdk \ extras \ android \ support \ v7 \ gridlayout, click OK:


The import package is complete, and you need to add this item to our project:



Click OK:


If you see this, it means that we have successfully added it! GridLayout can also be used in earlier versions!



But when used, the tag is written as follows :!!!

<Android. support. v7.widget. GridLayout>




The last two sentences are as follows:

Well, the introduction to GridLayout is here ~



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.