Android GridView-滚动时随机放置

Android GridView-滚动时随机放置,第1张

概述我正在尝试使用gridview使用this教程进行一些菜单设置.不幸的是,当我滚动菜单时,菜单项的位置会随机变化.我正在使用.xml显示图像和标题.顺便说一句:有什么办法可以对GridView进行排序?publicViewgetView(intposition,ViewconvertView,ViewGroupparent){LayoutInf

我正在尝试使用grIDvIEw使用this教程进行一些菜单设置.

不幸的是,当我滚动菜单时,菜单项的位置会随机变化.
我正在使用.xml显示图像和标题.

顺便说一句:有什么办法可以对GrIDVIEw进行排序?

public VIEw getVIEw(int position, VIEw convertVIEw, VIEwGroup parent) {    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);    VIEw grIDVIEw;    if (convertVIEw == null) {     String tmp = menuItems[position];        grIDVIEw = new VIEw(context);        grIDVIEw = inflater.inflate(R.layout.menuitem, null);        TextVIEw label = (TextVIEw) grIDVIEw.findVIEwByID(R.ID.menuitem_label);        label.setText(context.getString(context.getResources().getIDentifIEr("string/txt_"+tmp, null, context.getPackagename())));        ImageVIEw img = (ImageVIEw) grIDVIEw.findVIEwByID(R.ID.menuitem_image);     SVG svg_img = SVGParser.getSVGFromresource(context.getResources(), context.getResources().getIDentifIEr("raw/"+tmp, null, context.getPackagename()));     if (svg_img != null)        img.setimageDrawable(svg_img.createPictureDrawable());  } else {     grIDVIEw = (VIEw) convertVIEw;  }    return grIDVIEw;}

解决方法:

 public VIEw getVIEw(int position, VIEw convertVIEw, VIEwGroup parent) {        VIEw grIDVIEw;            if (convertVIEw == null) {  // if it's not recycled, initialize some attributes             LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);            grIDVIEw = inflater.inflate(R.layout.menuitem, null);           }           else           {              grIDVIEw= convertVIEw;           }         TextVIEw label = (TextVIEw) grIDVIEw.findVIEwByID(R.ID.menuitem_label);        label.setText(context.getString(context.getResources().getIDentifIEr("string/txt_"+tmp, null, context.getPackagename())));    ImageVIEw img = (ImageVIEw) grIDVIEw.findVIEwByID(R.ID.menuitem_image);     SVG svg_img = SVGParser.getSVGFromresource(context.getResources(),   context.getResources().getIDentifIEr("raw/"+tmp, null, context.getPackagename()));    img.setimageDrawable(svg_img.createPictureDrawable());        return grIDVIEw;    }

请研究有关grIDvIEws和回收的更多信息.网络中有大量的教程,以及堆栈溢出

我只是重新创建您的代码.我还没有尝试过

总结

以上是内存溢出为你收集整理的Android GridView-滚动时随机放置全部内容,希望文章能够帮你解决Android GridView-滚动时随机放置所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1085609.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存