Android entry eighth of the GridView (nine chart)

Source: Internet
Author: User

GridView and ListView are more commonly used multi-control layout, and GridView is the first choice to implement nine chart! This article is about how to use the GridView to implement the nine diagram. The use of a lot of the GridView, the most online introduction of the method is to implement a imageadapter inherited Baseadapter, and then for the GridView use, similar to this method of this article no longer repeat, This article describes the GridView usage in front of the ListView in the very similar .... Also is I lazy, hee hee hehe ....

First to post the results of this article's Code run:

This article requires the addition/modification of 3 files: Main.xml, Night_item.xml, Java source code.

Main.xml source code as follows, itself is a girdview, for loading item:

<?xml version= "1.0" encoding= "Utf-8"? ><gridview xmlns:android= "http://schemas.android.com/apk/res/ Android "android:id=" @+id/gridview "android:layout_width=" fill_parent "android:layout_height=" Fill_parent "Android : numcolumns= "Auto_fit" android:verticalspacing= "10DP" android:horizontalspacing= "10DP" android:columnwidth= "90DP" Android:stretchmode= "ColumnWidth" android:gravity= "center"/>

  

Describe some of the properties inside:

Android:numcolumns= "Auto_fit", the GridView column number is set to Automatic

Android:columnwidth= "90DP", width of each column, which is the width of item
Android:stretchmode= "ColumnWidth", Zoom and column size synchronization
Android:verticalspacing= "10DP", the margin between two lines, such as: line One (no.0~no.2) and row two (no.3~no.5) spacing is 10DP
Android:horizontalspacing= "10DP", the margin between two columns.

The next step is to introduce Night_item.xml, which is similar to the Imageitem.xml in the previous listview:

<?xml version="1.0"encoding="Utf-8"?><relativelayout xmlns:android="http://schemas.android.com/apk/res/android"Android:layout_height="wrap_content"Android:paddingbottom="4dip"Android:layout_width="fill_parent"><ImageView android:layout_height="wrap_content"Android:id="@+id/itemimage"Android:layout_width="wrap_content"Android:layout_centerhorizontal="true"> </ImageView><TextView android:layout_width="wrap_content"Android:layout_below="@+id/itemimage"Android:layout_height="wrap_content"Android:text="TextView01"Android:layout_centerhorizontal="true"Android:id="@+id/itemtext"></TextView></RelativeLayout>

The last is the source code of Java, but also with the previous ListView Java source is very similar, but more "selected" Event Processing:

    public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.main);                GridView GridView = (GridView) Findviewbyid (R.id.gridview); Generate a dynamic array and transfer to data arraylist

  

Android entry eighth of the GridView (nine chart)

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.