New ui-layout GridLayout (Grid layout) detailed

Source: Internet
Author: User

New ui-layout GridLayout (Grid layout) detailed

--Reprint Please indicate source: Coder-pig, welcome reprint, do not use for commercial use!


Piglet Android Development Exchange Group has been established, welcome everyone to join, both novice, rookie, Big God can, piglet a person's

Strength is limited after all, the writing out of things will certainly have a lot of flaws, welcome to point out, brainstorm, let the pig's blog

More detailed, help more people, O (∩_∩) o Thank you!

Piglet Android Development Exchange Group: Piglet Android Development Exchange Group Group number: 421858269

new Android UI Instance Daquan directory: http://blog.csdn.net/coder_pig/article/details/42145907


Introduction to this section:

The layout to be introduced today is a new layout introduced after Android 4.0, and the Tablelayout (table layout) you learned earlier

A bit similar, but he has a lot of things that the former does not, but also more useful,

1) You can set the arrangement of the components in the layout yourself

2) You can customize how many rows the grid layout has, how many columns

3) You can directly set the component to a column in a row

4) You can set the component to span several rows or columns

In addition to the above, this section will also give you the use of GridLayout problems encountered, and how to resolve the low version

How the SDK uses the GridLayout Method! Let's start with the lessons in this section!



1) Related attribute graph:




2) Use example: the 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_colu Mnspan= "4" android:text= "0" android:textsize= "50sp" android:layout_marginleft= "5DP" an droid:layout_marginright= "5DP"/> <button android:text= "fallback" Android:layout_columnspa N= "2" android:layout_gravity= "Fill"/> <button android:text= "Empty" Andro Id:layout_columnspan= "2" android:layout_gravity= "Fill"/> <button Android:tex      t= "+"/> <button     android:text= "1"/> <button android:text= "2"/> <button A ndroid: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_cont          Ent "android:text=". "   /> <button android:text= "0"/> <button android:text= "="/>   </GridLayout>


Code parsing:

The code is simple, just fallback with clear buttons across two columns, while others are added directly, by default each component is

In one row, there's another thing to note:

We pass: Android:layout_rowspan with the Android:layout_columnspan sets the component across

If you want the component to fill a row or column that crosses across rows or columns, you need to add the following attribute:

android:layout_gravity = "Fill" !! Just like this computer shows the number of parts!



3) Usage Induction:

①gridlayout use a dashed line to divide the layout into rows, columns, and cells, while also supporting rows and columns for staggered arrangement

② Use process:

Step 1: Define how the component is android:orientation horizontally or vertically, and how many rows and columns to set

Step 2: Set the row or column where the component is located, remember that it is calculated from 0, do not set the default per component one row

Step 3: Set the component across several rows or columns; After Setup, you need to set a fill: android:layout_gravity = "Fill"



4) Where to pay attention to the use of GridLayout:

because Girdlayout was released after 4.0, so MINSDK version should be changed to 14 or above ,

Otherwise write the layout code, this thing will be inexplicably error, said to find this gridlayout,

Of course, if you want the lower version compatible, it is necessary to look at the following content!



5) How the low version SDK uses GridLayout:

The workaround is simple: just import the GridLayout package of the V7 package!

V7 packages are generally under the SDK: under the Sdk\extras\android\support\v7\gridlayout directory

If you don't have one, you can also download it here:

Gridlayout_v7_jay Package Download: http://pan.baidu.com/s/1kTC2s3l


Follow the process below to complete the guide package:


Find sdk\extras\android\support\v7\gridlayout and click OK:


The guide package is finished, and the item is added to our project:



After selecting Click OK:


See here, it means we added success! The lower version can also be used GridLayout!



But when used, the label is written like this:!!!

<android.support.v7.widget.GridLayout>




Finally say two words:

Well, the introduction to GridLayout is here.



New ui-layout GridLayout (Grid layout) detailed

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.