Android GridLayout layout, androidgridlayout

Source: Internet
Author: User

Android GridLayout layout, androidgridlayout

A GridLayout is added after android4.0. It uses virtual line to divide the layout into rows, columns, and cells. It also supports the staggered arrangement of controls on rows and columns. In fact, it uses methods and LinearLayout, relativelayout is similar, but it only has some special attributes.

The layout policy of GridLayout is divided into the following three parts:

First, it is the same as the LinearLayout layout. It can also be divided into two ways: horizontal and vertical. By default, it is a flat layout. A control is arranged from left to right, but android is specified: after columnCount sets the attribute of the number of columns, the control Automatically sorts the columns with line breaks. On the other hand, for the child control in the GridLayout layout, the display is set according to the wrap_content method by default, which only needs to be explicitly declared in the GridLayout layout.

 

 

Second, to specify that a widget is displayed in a fixed row or column, you only need to set the android: layout_row and android: layout_column attributes of the Child widget. However, you must note that: android: layout_row = "0" indicates starting from the first line. android: layout_column = "0" indicates starting from the first column. This is similar to the assignment of one-dimensional arrays in programming languages.

 

 

Finally, if you need to set a control to span multiple rows or columns, you only need to set the android: layout_rowSpan or layout_columnSpan attribute of the Child control to a value, and then set its layout_gravity attribute to fill, the previous setting indicates the number of rows or columns that the control spans. The last setting indicates that the control fills up the entire row or column that the control spans.

It can be said that after GridLayout is used, tablelayout is no longer needed, and GridLayout effectively reduces the layout depth and improves the overall performance quality of the app.

The following is done using GridLayout:

  

The layout code is as follows:

<?xml version="1.0" encoding="utf-8"?><GridLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:background="@drawable/digital_bg"    android:columnCount="6"    android:orientation="horizontal"    android:padding="16dip"    android:rowCount="3">    <TextView        android:id="@+id/edit_input"        android:layout_columnSpan="5"        android:layout_gravity="fill"        android:textSize="14sp"        android:gravity="center_vertical"        android:paddingLeft="8dip"        android:background="@drawable/input_bg" />    <ImageButton        android:id="@+id/delete"        android:layout_marginLeft="16dip"        android:background="@drawable/delete_btn_style" />           <ImageButton        android:id="@+id/num_1"        android:layout_marginTop="16dip"        android:background="@drawable/num_1_btn_style" />    <ImageButton        android:id="@+id/num_2"        android:layout_marginLeft="16dip"        android:layout_marginTop="16dip"        android:background="@drawable/num_2_btn_style" />    <ImageButton        android:id="@+id/num_3"        android:layout_marginLeft="16dip"        android:layout_marginTop="16dip"        android:background="@drawable/num_3_btn_style" />    <ImageButton        android:id="@+id/num_4"        android:layout_marginLeft="16dip"        android:layout_marginTop="16dip"        android:background="@drawable/num_4_btn_style" />    <ImageButton        android:id="@+id/num_5"        android:layout_marginLeft="16dip"        android:layout_marginTop="16dip"        android:background="@drawable/num_5_btn_style" />          <ImageButton        android:id="@+id/confirm"        android:layout_marginLeft="16dip"        android:layout_marginTop="16dip"        android:layout_rowSpan="2"        android:background="@drawable/confirm_btn_style" />    <ImageButton        android:id="@+id/num_6"        android:layout_marginTop="16dip"        android:background="@drawable/num_6_btn_style" />    <ImageButton        android:id="@+id/num_7"        android:layout_marginLeft="16dip"        android:layout_marginTop="16dip"        android:background="@drawable/num_7_btn_style" />    <ImageButton        android:id="@+id/num_8"        android:layout_marginLeft="16dip"        android:layout_marginTop="16dip"        android:background="@drawable/num_8_btn_style" />    <ImageButton        android:id="@+id/num_9"        android:layout_marginLeft="16dip"        android:layout_marginTop="16dip"        android:background="@drawable/num_9_btn_style" />    <ImageButton        android:id="@+id/num_0"        android:layout_marginLeft="16dip"        android:layout_marginTop="16dip"        android:background="@drawable/num_0_btn_style" /></GridLayout>

 

 

 

References: http://blog.csdn.net/pku_android/article/details/7343258

 

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.