Android Development-Fix custom GridView Height first item Height exception problem

Source: Internet
Author: User

Problem Description:

Before writing, the problem of the map, the problem, such as the GridView first item of the custom height display is not normal (again loaded and normal), not a preset height:

650) this.width=650; "style=" WIDTH:247PX;HEIGHT:377PX; "title=" QQ picture 20150915140447.png "alt=" Wkiol1x3t03buqyqaadxrxtwmys462.jpg "src=" http://s3.51cto.com/wyfs02/M02/73/32/ Wkiol1x3t03buqyqaadxrxtwmys462.jpg "width=" 345 "height=" 550 "/>

Workaround:

The first thing to declare, this GridView adapter is baseadapter, in the definition of the adapter GetView method, the main attention to the code/***********/markup Place, the following paste my GetView method:

Public view getview (int position, view convertview, viewgroup parent)   {      girdholder holder;      if (ConvertView  == null) {    holder = new girdholder ();     Convertview = layoutinflater.from (Getapplication ()). Inflate (R.layout.gridview_item, null);     //set item ' S height      gridview.layoutparams  param = new gridview.layoutparams (                   android.view.viewgroup.layoutparams.match_parent, ( Gvlist.getheight ()-(1+level) *16)/level);     convertview.setlayoutparams (param);         holder.imgView =  (ImageView)  convertview.findviewbyid (r.id.image);   &nbSp; convertview.settag (holder);   }else{    holder =  ( Girdholder)  convertview.gettag ();     //fix the problem of first  item ' s height is not normal    /****************** Be sure to write the height code again in this position ******************************/    convertview.setlayoutparams (new  Gridview.layoutparams (                   android.view.viewgroup.layoutparams.match_parent, (Gvlist.getheight ()-(1+level) *16)/ Level));    /************************************************/      }   if (status[position] == 0) {     Holder.imgView.setImageResource (R.drawable.smile_yellow);   }else{     Holder.imgView.setImageResource (R.drawable.smile_bule);   }   return convertview;  } 

And then post the solution:

650) this.width=650; "style=" width:261px;height:393px; "title=" QQ picture 20150915141517.png "alt=" Wkiom1x3t4aa_ Lt8aadoazxtd6c937.jpg "src=" http://s3.51cto.com/wyfs02/M00/73/35/wKiom1X3t4aA_lT8AADOAZXtd6c937.jpg "width=" 302 " height= "385"/>

This article is from the "alan_y (upspringing)" blog, so be sure to keep this source http://alany.blog.51cto.com/6125308/1694937

Android Development-Fix custom GridView Height first item Height exception problem

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.