加载图片在滑动或notifyDataSetChanged时闪动"/>
ImageLoader加载图片在滑动或notifyDataSetChanged时闪动
在网上搜了一圈,发现解决方法如下:
- 在Adapter的getView方法里对Imageview绑定地址,在比对地址进行加载图片
//image为数据实体,uri为请求地址,options为配置参数viewHolder.imageview.setTag(image.getPath());if(image.getPath().equals(viewHolder.imageview.getTag())){imageLoader.displayImgdisplayImage(uri, imageView, options);}
- 设置ImageLoaderConfiguration,加大缓存大小
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this) .memoryCacheExtraOptions(480, 800) // default = device screen dimensions .discCacheExtraOptions(480, 800, CompressFormat.JPEG, 75, null) .taskExecutor(...) .taskExecutorForCachedImages(...) .threadPoolSize(3) // default .threadPriority(Thread.NORM_PRIORITY - 1) // default .tasksProcessingOrder(QueueProcessingType.FIFO) // default .denyCacheImageMultipleSizesInMemory() .memoryCache(new LruMemoryCache(2 * 1024 * 1024)) .memoryCacheSize(2 * 1024 * 1024) .memoryCacheSizePercentage(13) // default .discCache(new UnlimitedDiscCache(cacheDir))// default .discCacheSize(50 * 1024 * 1024) // 缓存大小 .discCacheFileCount(100) // 缓存文件数目 .discCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default .imageDownloader(new BaseImageDownloader(context)) // default .imageDecoder(new BaseImageDecoder()) // default .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default .writeDebugLogs() .build();
- 设置DisplayImageOptions
DisplayImageOptions options = new DisplayImageOptions.Builder().showImageOnLoading(imageLoadingResId).showImageForEmptyUri(imageErrorResId).showImageOnFail(imageErrorResId).cacheInMemory(true) //加载本地图片不需要再做SD卡缓存,只做内存缓存即可.considerExifParams(true)//设置显示器为SimpleBitmapDisplayer.displayer(new SimpleBitmapDisplayer()).bitmapConfig(Bitmap.Config.RGB_565).build();
- 还有就是设置ImageLoader.getInstance().displayImage(…)改为
ImageLoader.getInstance().loadImage(…);
然而解决问题的是下面这样的加载
ImageAware imageAware = new ImageViewAware(imageView, false);
ImageLoader.getInstance().displayImage(uri, imageAware, options);
很多开源库,我们可以通过像作者提交issues,也可以查看作者对issues的回答来决解遇到的问题
更多推荐
ImageLoader加载图片在滑动或notifyDataSetChanged时闪动
发布评论