Android 0 Basics Section 32nd: New GridLayout Grid layout

Source: Internet
Author: User

Original: Android 0 basic Introductory section 32nd: New GridLayout Grid layout

The main study in this issue is the grid layout is the new Android 4.0 layout, and the previous Tablelayout table layout is a bit similar, but he has a lot of former things, but also more useful.

I. Understanding GridLayout

The grid layout realizes the interleaved display of the control, avoids the influence of the layout nesting on the device performance, and is more conducive to the development of free layout. Grid layout divides the drawing area into rows, columns, and cells with an infinite set of lines, and specifies how the control's display area and control are displayed in that area

The following table shows the XML attributes commonly used in GridLayout and the related method descriptions.

To control the layout distribution of the sub-components in the GridLayout layout container, GridLayout provides an inner class: Gridlayout.layoutparams, which provides a large number of XML properties to control the layout distribution of sub-components in a GridLayout layout container.

The following table shows the XML attributes and related methods commonly used by Gridlayout.layoutparams.

Ii. examples

Next, learn the usage of GridLayout using a simple example program.

Also using the Widgetsample project, continue to use the Activity_main.xml file in the app/main/res/layout/directory, where the following code snippet is populated:

<?XML version= "1.0" encoding= "Utf-8"?><GridLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:columncount= "4"Android:rowcount= "7">    <TextViewAndroid:id= "@+id/result_tv"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_columnspan= "4"Android:background= "#eee"Android:text= "0"Android:textcolor= "#000"android:textsize= "50SP" />    <ButtonAndroid:id= "@+id/clear_btn"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_columnspan= "4"Android:text= "Clear" />    <ButtonAndroid:id= "@+id/one_btn"Android:layout_columnweight= "1"Android:layout_rowweight= "1"Android:text= "1" />    <ButtonAndroid:id= "@+id/two_btn"Android:layout_columnweight= "1"Android:layout_rowweight= "1"Android:text= "2" />    <ButtonAndroid:id= "@+id/three_btn"Android:layout_columnweight= "1"Android:layout_rowweight= "1"Android:text= "3" />    <ButtonAndroid:id= "@+id/devide_btn"Android:layout_columnweight= "1"Android:layout_rowweight= "1"Android:text="/" />    <ButtonAndroid:id= "@+id/four_btn"Android:layout_columnweight= "1"Android:layout_rowweight= "1"Android:text= "4" />    <ButtonAndroid:id= "@+id/five_btn"Android:layout_columnweight= "1"Android:layout_rowweight= "1"Android:text= "5" />    <ButtonAndroid:id= "@+id/six_btn"Android:layout_columnweight= "1"Android:layout_rowweight= "1"Android:text= "6" />    <ButtonAndroid:id= "@+id/multiply_btn"Android:layout_columnweight= "1"Android:layout_rowweight= "1"Android:text= "X" />    <ButtonAndroid:id= "@+id/seven_btn"Android:layout_columnweight= "1"Android:layout_rowweight= "1"Android:text= "7" />    <ButtonAndroid:id= "@+id/eight_btn"Android:layout_columnweight= "1"Android:layout_rowweight= "1"Android:text= "8" />    <ButtonAndroid:id= "@+id/nine_btn"Android:layout_columnweight= "1"Android:layout_rowweight= "1"Android:text= "9" />    <ButtonAndroid:id= "@+id/minus_btn"Android:layout_columnweight= "1"Android:layout_rowweight= "1"Android:text="-" />    <ButtonAndroid:id= "@+id/zero_btn"Android:layout_columnspan= "2"Android:layout_columnweight= "1"android:layout_gravity= "Fill"Android:layout_rowweight= "1"Android:text= "0" />    <ButtonAndroid:id= "@+id/point_btn"Android:layout_columnweight= "1"Android:layout_rowweight= "1"Android:text="." />    <ButtonAndroid:id= "@+id/plus_btn"Android:layout_columnweight= "1"Android:layout_rowspan= "2"Android:layout_rowweight= "1"Android:text="+" />    <ButtonAndroid:id= "@+id/equal_btn"Android:layout_columnspan= "3"Android:layout_columnweight= "1"Android:layout_rowweight= "1"Android:text="=" /></GridLayout>

To run the program, you can see the interface effect shown:

So, have you mastered the six kinds of interface layouts in Android that you've learned? Be sure to do more hands-on exercises oh, start with the next phase to learn about Android event processing.

Come here today, if you have any questions welcome message to discuss together, also welcome to join the Android 0 Basic introductory Technical discussion group, grow together!

This article copyright for the public Share talent show (Shareexpert)--Xin 鱻 all, if necessary reprint please contact the author authorized, hereby declare!

Past period Summary share:

Android 0 Basics Introduction 1th: Android's past life

Android 0 Basics Section 2nd: Android system Architecture and application components those things

Android 0 Basics Section 3rd: Bring you up to talk about Android development environment

Android 0 Basics 4th: Installing and configuring the JDK correctly Ko fu the first trick

Android 0 Basics 5th: Use ADT bundles to easily meet the goddess

Android 0 Basics 6th: Configuration Optimization SDK Manager, official dating goddess

Android 0 Basics 7th: Take care of Android simulator and start the Sweet journey

Android 0 Basics 8th: HelloWorld, the starting point for my first trip

Android 0 Basics 9th: Android app, no code can be developed

Android 0 Basics Section 10th: Development IDE Big upgrade, finally ushered in Android Studio

Android 0 Basics Introductory Section 11th: Simple steps to take you to fly, run Android Studio project

Android 0 Basics 12th: Get familiar with the Android studio interface and start selling

Android 0 Basics 13th: Android Studio Configuration optimization to create a development tool

Android 0 Basics 14th: Using high-speed genymotion, stepping into the rocket era

Android 0 Basics Section 15th: Mastering the Android Studio project structure, sailing

Android 0 Basics Section 16th: Android User Interface Development overview

Android 0 Basics Section 17th: TextView Properties and Methods Daquan

Android 0 Basics Section 18th: EditText properties and how to use them

Android 0 Basics section 19th: Button usage explained

Android 0 Basics Section 20th: checkbox and RadioButton Usage Daquan

Android 0 Basics Section 21st: ToggleButton and switch usage Daquan

Android 0 Basics Section 22nd: ImageView's properties and methods Daquan

Android 0 Basics Section 23rd: ImageButton and Zoombutton use Daquan

Android 0 Basics Section 24th: Customize view simple to use to create your own controls

Android 0 Basics Section 25th: Simple and most commonly used linearlayout linear layouts

Android 0 Basics Section 26th: Two alignments, layout_gravity and gravity differ greatly

Android 0 Basics section 27th: Using padding and margin correctly

Android 0 Basics Section 28th: Easy to master relativelayout relative layout

Android 0 Basics 29th: Use tablelayout table layouts

Android 0 Basics 30th: Two minutes master Framelayout frame layout

Android 0 Basics Section 31st: absolutelayout absolute Layout with less

Android 0 Basics Section 32nd: New GridLayout Grid layout

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.