Android 4.0 New components: GridLayout detailed

Source: Internet
Author: User
Tags rowcount

In Android 4.0 (API 14), a completely new component GridLayout, which inherits from LinearLayout, is used for the layout of the Web format.

In some ways, GridLayout is similar to Tablelayout and the GridView. His strong point is that you can specify that each cell "spans" several cells or "vertically" several cells, which is similar to the <table> tags in HTML.

Several important properties of GridLayout:

RowCount: Number of rows

ColumnCount: Number of columns

GridLayout's child view will be able to apply attributes:

Layout_rowspan: vertically across several cells

Layout_columnspan: horizontally across several cells

Also, GridLayout's child view can not specify Layout_width and Layout_height (similar to tablelayout)


Using GridLayout, you can easily develop a calculator-like page that simplifies code, simplifies nesting levels, improves performance, and adapts to better performance than using LinearLayout.

Layout code:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "android:orientation=" vertical "android:padding=" 8DP "android:layout_width=" Match_parent "Android:layo ut_height= "Match_parent" > <textview android:layout_width= "wrap_content" android:layout_height= "wrap _content "android:textsize=" 18sp "android:text=" calculator "/> <gridlayout android:layout_width=" WR        Ap_content "android:layout_height=" Wrap_content "android:rowcount=" 5 "android:columncount=" 4 "        android:layout_margin= "4DP" > <button android:text= "C"/> <button android:text= "Del"/>        <button android:text= "/"/> <button android:text= "x"/> <button android:text= "7"/>        <button android:text= "8"/> <button android:text= "9"/> <button android:text= "-"/> <button android:text= "4"/>        <button android:text= "5"/> <button android:text= "6"/> <button android:text= "+"/>        <button android:text= "1"/> <button android:text= "2"/> <button android:text= "3"/> <button android:text= "=" android:layout_gravity= "Fill" android:layout_rowspan= "2"/&        Gt <button android:text= "0" android:layout_gravity= "Fill" android:layout_columnspan= "2"/ > <button android:text= "."/> </GridLayout></LinearLayout>


Android 4.0 New components: GridLayout 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.