The following is the GridView control, where each row is placed four, so the width is removed by 4. The interface shown below is quite beautiful.
public class Hotsearchadapter extends Baseadapter {private layoutinflater inflater;private list<app> infos; Private Context Context;public Hotsearchadapter (context context, list<app> Infos) {super (); This.infos = Infos; This.context = Context;this.inflater = Layoutinflater.from (context); Initwin ();} @Overridepublic int GetCount () {if (infos! = null && infos.size () > 0) {return infos.size ();} return 0;} @Overridepublic Object getItem (int position) {if (infos! = null && infos.size () > 0) {return Infos.get (position );} return null;} @Overridepublic long Getitemid (int position) {return position;} @Overridepublic view GetView (int position, view Convertview, ViewGroup parent) {Dataholder holder;if (Convertview = = null) {Convertview = inflater.inflate (R.layout.hot_search_gv_item, null); holder = new Dataholder (); holder.iv_image = ( ImageView) Convertview.findviewbyid (r.id.iv_image); Convertview.settag (holder);} else {holder = (Dataholder) Convertview.gettag ();} APP mApp =Infos.get (position); int pad = (int) (2*density); convertview.setpadding (pad, pad, pad, pad); Convertview.setlayoutparams (New Abslistview.layoutparams (WIDTHPIXELS/4,WIDTHPIXELS/4)); return ConvertView;} Public final class Dataholder {public ImageView iv_image;} private void Initwin () {WindowManager manager = (WindowManager) context.getsystemservice (context.window_service);D Isplaymetrics metrics = new Displaymetrics (); Manager.getdefaultdisplay (). Getmetrics (metrics);d ensity = Metrics.density;widthpixels = Metrics.widthpixels;} private float density;private int widthpixels;}
GridView subkey is the same length as the width