1. Introduction
Is the application of the gridview component! This component can be used to implement all the functions of jiugongge.
2.
3. xml file
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <GridView android:id="@+id/gridview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:numColumns="auto_fit" android:columnWidth="100sp" android:stretchMode="columnWidth" android:gravity="center" /> </FrameLayout>
4. Java code
Package Wei. ye. g1; import android. app. activity; import android. content. context; import android. OS. bundle; import android. view. view; import android. view. viewgroup; import android. widget. baseadapter; import android. widget. gridview; import android. widget. imageview; public class wangge extends activity {Private Static int [] images = {R. drawable. baos, R. drawable. caoc, R. drawable. chenyj, R. drawable. chenyy, R. drawable. gouj, R. drawable. guany, R. drawable. hanx, R. drawable. LP, R. drawable. liub, R. drawable. qinq, R. drawable. tiemz, R. drawable. wus, R. drawable. xiangy, R. drawable. yuef, R. drawable. zhaoky, R. drawable. zhugl, R. drawable. xis, R. drawable. yingz}; gridview GV; @ override protected void oncreate (bundle savedinstancestate) {// todo auto-generated method stub super. oncreate (savedinstancestate); setcontentview (R. layout. wangge); settitle ("Grid View"); GV = (gridview) findviewbyid (R. id. gridview); GV. setadapter (New imageadapter (this);} public class imageadapter extends baseadapter {private context mcontext; Public imageadapter (context c) {mcontext = C;} @ override public int getcount () {return images. length ;}@ override public object getitem (INT position) {return NULL ;}@ override public long getitemid (INT position) {return 0 ;}// create an imageview, and set the corresponding image. images is the public view getview (INT position, view convertview, viewgroup parent) {imageview; // system. out. println (convertview); // If -- else in order to save memory space, reduce the creation of objects if (convertview = NULL) {imageview = new imageview (mcontext ); // set the size of the image to be displayed. imageview. setlayoutparams (New gridview. layoutparams (120,120); imageview. setscaletype (imageview. scaletype. center_crop); imageview. setpadding (8, 8, 8, 8);} else {imageview = (imageview) convertview;} imageview. setimageresource (images [position]); Return imageview ;}}}