GridView is a data display control in Android. First try it out.
This is the effect of displaying only images in the GridView. Source code download http://www.bkjia.com/uploadfile/2012/0425/20120425103107648.rar
The following describes the GridView in detail.
I. Introduction
The Item is displayed in a two-dimensional scrollable mesh. The Item comes from the related ListAdapter.
Ii. Important Methods
GetStretchMode (): Get the Extended Mode of the GridView.
OnKeyDown (int keyCode, KeyEvent event): Default KeyEvent. Callback. onKeyMultiple ()
Iii. Specific applications
1. description in the layout File
<GridView xmlns: android = "http://schemas.android.com/apk/res/android" android: id = "@ + id/grid"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: padding = "10dp"
Android: verticalSpacing = "10dp"
Android: horizontalSpacing = "10dp"
Android: numColumns = "auto_fit"
Android: columnWidth = "60dp"
Android: stretchMode = "columnWidth"
Android: gravity = "center"
/>
2. Program usage
Private GridView mGrid;
MGrid = (GridView) findViewById (R. id. grid );
3. Define the adapter
Public class extends adapter extends BaseAdapter {
Public writable adapter (){
}
Public View getView (int position, View convertView, ViewGroup parent ){
ImageView I;
If (convertView = null ){
I = new ImageView (GridDemo. this );
I. setScaleType (ImageView. ScaleType. FIT_CENTER );
I. setLayoutParams (new GridView. LayoutParams (50, 50 ));
} Else {
I = (ImageView) convertView;
}
ResolveInfo info = mApps. get (position );
I. setImageDrawable (info. activityInfo. loadIcon (getPackageManager ()));
Return I;
}
Public final int getCount (){
Return mApps. size ();
}
Public final Object getItem (int position ){
Return mApps. get (position );
}
Public final long getItemId (int position ){
Return position;
}
}
4. Application Adapter
MGrid. setAdapter (new container adapter ());
5. retrieve images
Private void loadApps (){
Intent mainIntent = new Intent (Intent. ACTION_MAIN, null );
MainIntent. addCategory (Intent. CATEGORY_LAUNCHER );
MApps = getPackageManager (). queryIntentActivities (mainIntent, 0 );
}
From the eternal memory