【问题标题】:Android gridview containing NetworkImageView from volley library duplicates image on scroll包含来自 volley 库的 NetworkImageView 的 Android gridview 在滚动时重复图像
【发布时间】:2016-04-12 23:09:48
【问题描述】:

我正在使用 NetworkImageView 从我的 Gridview 中的 Url 加载图像。

第一次可以正常工作,但是在 Scroll 上,网格项目开始在随机位置复制。

下面是我的 GridView 适配器代码:

 @Override
public View getView(int position, View convertView, ViewGroup parent) {

    if (convertView == null) {
        LayoutInflater mInflater = (LayoutInflater)
                context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        convertView = mInflater.inflate(R.layout.grid_item, null);
    }

    NetworkImageView imageViewBand = (NetworkImageView) convertView.findViewById(R.id.imageView_grid_item);
    TextView textViewBand = (TextView) convertView.findViewById(R.id.textView_grid_item);
    imageViewBand.setDefaultImageResId(R.drawable.college_default_icon_grid_view);
    imageViewBand.setAdjustViewBounds(true);
    imageViewBand.setImageUrl(Constants.schoolImageUrl, AppController.getInstance(context).getImageLoader());

    textViewBand.setText(schoolArrayList.get(position).getSchoolName());

    return convertView;
}

网格项中的文本工作正常,但仅在凌空图像加载器导致图像重复时出现此问题。

请帮忙。

【问题讨论】:

  • 您的问题是您正在重用滚动视图,但在加载新图像之前您没有将 imageViewBand 图像 url 重置为 null。所以你要做的就是在重用它之前将图像 url 设置为 null
  • 非常感谢!被困在过去的 1 小时里...... :)

标签: android gridview android-volley networkimageview


【解决方案1】:

您的问题是您正在重用滚动视图,但在加载新图像之前您没有将 imageViewBand 图像 url 重置为 null。所以你要做的就是在重用它之前将图像 url 设置为 null

下次尝试使用 GridLayoutManager 实现 RecyclerView,因为使用 RecyclerView 重用视图是自动完成的

【讨论】:

猜你喜欢
  • 2014-08-13
  • 2017-04-09
  • 2015-11-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多