Android的异步加载图片列表视图中 - 图像闪烁 [英] Android Async loading Images in Listview - images are blinking

查看:390
本文介绍了Android的异步加载图片列表视图中 - 图像闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在挣扎,在ListView中异步加载图像,因为他们正在加载时,他们中的一些闪烁(他们被另一个加载图像取代),其中一些在错误的项目显示。

I have been struggling with asynchronously loading images in ListView, because while they're loading, some of them are blinking (they're are replaced by another loaded image) and some of them are showed in wrong items.

类下载图片:

class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
  ImageView bmImage;

  public DownloadImageTask(ImageView bmImage) {
      this.bmImage = bmImage;
  }

  protected Bitmap doInBackground(String... urls) 
  {
      String urldisplay = urls[0];
      Bitmap mIcon11 = null;

      try 
      {
        InputStream in = new java.net.URL(urldisplay).openStream();
        mIcon11 = BitmapFactory.decodeStream(in);
      } 
      catch (Exception e) {}

      return mIcon11;
  }

  protected void onPostExecute(Bitmap result) {
      bmImage.setImageBitmap(result);
  }
}

呼吁每一个项目,当我到ListView的分配数据:

Calls for each item, when I am assigning data to ListView:

ImageView image = (ImageView)view.findViewById(R.id.imageView);
TextView title = (TextView)view.findViewById(R.id.txtTitle);

new DownloadImageTask(image).execute(data.image);
title.setText(data.title);

我应该怎么做不同?

What should I do differently?

推荐答案

在除了什么Forin说,有许多库,真正帮助了上这样的事情。我此刻的个人最喜欢的是AQuery:

In addition to what Forin has said, there are many libraries that really help out on things like this. My personal favorite at the moment is AQuery:

的https://$c$c.google.com/p/android -query /

假设你有一个ImageView的,你想下载的图像,并设置ImageView的来保存图像。听起来有点难度吧?与AQuery这是在一条线完成:

Let's say you have an ImageView and you want to download an image and set the imageView to hold that image. Sounds sort of difficult, right? With AQuery this is done in one line:

aq.id(R.id.name_of_image_view).image("http://url-of-image.com/image.png");

AQ 在这种情况下被宣布像这样的AQuery对象:

aq in this case is an AQuery object declared like so:

AQuery aq = new AQuery();

这篇关于Android的异步加载图片列表视图中 - 图像闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆