GridView ÊÇ AdapterView µÄÅÉÉúÀ࣬ AdapterView ÊÇ ViewGroup µÄÅÉÉúÀ࣬ ViewGroup ÊÇ View µÄÅÉÉúÀà¡£
ʲôÊÇ GridView £¿¹Ù·½µÄ˵·¨ÊÇ£º
A view that shows items in two-dimensional scrolling grid. The items in the grid come from the ListAdapter associated with this view
Õâ¾ä»°°üº¬ÒÔϼ¸¸öÒâ˼£º
+ GridView ÊÇÒ»¸ö¶þά¿É¹ö¶¯µÄÍø¸ñÊÓͼ
+ GridView ÖеÄÊý¾ÝÊÇÓÐÓëÖ®¹ØÁªµÄ ListAdapter ÌṩµÄ
ÏÂÃæ¾ÍÒ»¸ö¾ßÌåµÄÀý×ÓÀ´ËµÃ÷ GridView µÄÓ÷¨¡£
1. ´´½¨Ò»¸öÏîÄ¿£¬ÐÞ¸Ä main.xml ʹ֮ÈçÏ£º
< xml version = "1.0" encoding = "utf-8" >
android:id = "@+id/gridview"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"
android:background = "#333"
android:columnWidth = "90px"
android:numColumns = "auto_fit"
android:horizontalSpacing = "6px"
android:verticalSpacing = "6px"
android:stretchMode = "columnWidth"
android:gravity = "center" >
GridView >
2. ½«Ïà¹ØµÄͼƬÍÏÈë res/drawable-mdpi Îļþ¼ÐÖУº

ÒÔÉϸ÷ͼ¶ÔÓ¦µÄÎļþÃû·Ö±ðΪ£º
.aa.png, al.png, ar.png. au.png, cf.png, cn .png, dm .png, eu .png, fa .png, gr .png, hk .png, in .png, ma .png, pk .png, ru .png, sk .png, uk .png, us .png,
3. ×Ô¶¨Òå Adapter £¬Ê¹Ö®ÈçÏ£º
package com.pat.gui;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class ImageAdapter extends BaseAdapter
{
private Context ctx;
private int[] images =
{
R.drawable.aa, // Austria
R.drawable.al, // Algeria
R.drawable.ar, // Argentina
R.drawable.au, // Austrilia
R.drawable.cf, // Swizterland
R.drawable.cn, // China
R.drawable.dm, // Denmark
R.drawable.eu, // European Union
R.drawable.fa, // France
R.drawable.gr, // Greece
R.drawable.hk, // Hong Kong
R.drawable.in, // India
R.drawable.ma, // Macau
R.drawable.pk, // Pakistan
R.drawable.ru, // Russia
R.drawable.sk, // South Korea
R.drawable.uk, // United Kingdom
R.drawable.us // United States
};
public ImageAdapter(Context ctx)
{
this.ctx = ctx;
}
//@Override
public int getCount()
{
return images.length;
}
//@Override
public Object getItem(int position)
{
return images[position];
}
//@Override
public long getItemId(int position)
{
return images[po