GridView subkey is the same length as the width

Source: Internet
Author: User


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

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.