ListView图像未按顺序显示

时间:2014-06-06 20:46:37

标签: android listview universal-image-loader

我正在使用通用图像加载器在我的listView中显示缩略图但是当我快速向上/向下滚动图像时会发生相互影响,这很烦人请帮助我解决它... 谢谢 我的DisplayImage配置:

 DisplayImageOptions displayimageOptions = new   DisplayImageOptions.Builder().cacheInMemory(true).bitmapConfig(Bitmap.Config.RGB_565).
            delayBeforeLoading(1000) .cacheOnDisc(true).imageScaleType(ImageScaleType.EXACTLY)
            .resetViewBeforeLoading().build();

和ImageLoader配置:

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
    .threadPoolSize(15) 
    .threadPriority(Thread.NORM_PRIORITY) // default
    .tasksProcessingOrder(QueueProcessingType.FIFO) // default
    .memoryCacheSize(20 * 1024 * 1024)
    .memoryCacheSizePercentage(25) // default
    .discCacheSize(20 * 1024 * 1024)
    .discCacheFileCount(100)
    .discCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
    .build();

    ImageLoader.getInstance().init(config);

适配器的getView():

public View getView(int position, View convertView, ViewGroup parent) {
    View vi=convertView;
    if(convertView==null){
        vi = inflater.inflate(R.layout.list_layout, null);
    }
    TextView title = (TextView)vi.findViewById(R.id.tv2); // title
    final ImageView thumb_image=(ImageView)vi.findViewById(R.id.img); // thumb image

    HashMap<String, String> song = new HashMap<String, String>();
    song = data.get(position);

    // Setting all values in listview
    title.setText(song.get(DisplayMessage.KEY_TITLE));
    Log.w(null, song.get(DisplayMessage.KEY_THUMB_URL));
    ImageLoader imageLoader = ImageLoader.getInstance();
    Log.w("null",song.get(DisplayMessage.KEY_THUMB_URL));
    ImageSize targetSize = new ImageSize(70, 70);
  final  ImageAware imageAware = new ImageViewAware(thumb_image, false);
   // Utils.imageLoader.displayImage("file:///"+song.get(DisplayMessage.KEY_THUMB_URL), imageAware);
    imageLoader.loadImage("file:///"+song.get(DisplayMessage.KEY_THUMB_URL), targetSize, new SimpleImageLoadingListener() {
        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            // Do whatever you want with Bitmap
            imageAware.setImageBitmap(ThumbnailUtils.extractThumbnail(loadedImage, 70, 70));
        }
    });

    return vi;
}

1 个答案:

答案 0 :(得分:-1)

在你的getView()方法中,只需删除此if(convertView==null)条件,然后再尝试再次运行。就像下面这样 -

public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
//if(convertView==null){
    vi = inflater.inflate(R.layout.list_layout, null);
//}
TextView title = (TextView)vi.findViewById(R.id.tv2); // title
final ImageView thumb_image=(ImageView)vi.findViewById(R.id.img); // thumb image

HashMap<String, String> song = new HashMap<String, String>();
song = data.get(position);

// Setting all values in listview
title.setText(song.get(DisplayMessage.KEY_TITLE));
Log.w(null, song.get(DisplayMessage.KEY_THUMB_URL));
ImageLoader imageLoader = ImageLoader.getInstance();
Log.w("null",song.get(DisplayMessage.KEY_THUMB_URL));
ImageSize targetSize = new ImageSize(70, 70);
final  ImageAware imageAware = new ImageViewAware(thumb_image, false);
 // Utils.imageLoader.displayImage("file:///"+song.get(DisplayMessage.KEY_THUMB_URL), 
imageAware);
imageLoader.loadImage("file:///"+song.get(DisplayMessage.KEY_THUMB_URL), targetSize, new      
 SimpleImageLoadingListener() {
    @Override
    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
        // Do whatever you want with Bitmap
        imageAware.setImageBitmap(ThumbnailUtils.extractThumbnail(loadedImage, 70, 70));
    }
});
return vi;
}