ImageLoader加载图片在滑动或notifyDataSetChanged时闪动

编程入门 行业动态 更新时间:2024-10-15 06:20:00

ImageLoader<a href=https://www.elefans.com/category/jswz/34/1771433.html style=加载图片在滑动或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时闪动

本文发布于:2024-02-26 11:05:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1702259.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   图片   ImageLoader   notifyDataSetChanged

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!