ImageLoader 俩个比较坑的问题。

1.

   Android-Universal-Image-Loader是个图片缓存,异步加载,防止内存泄露的好东西 ,用起来非常的方便,于是跑到官网下载了,点击打开链接,当时完全是按照官方的Demo来搭建的,但是始终程序运行不起来,会报以下错误:

java.lang.RuntimeException: ImageLoader must be init with configuration before using

找了很久也没有找到问题的解决方法,最后在网上找到了最终的解决方案,只要加一句话:

imageLoader.init(ImageLoaderConfiguration.createDefault(MainActivity.this));

原来是没有初始化,奇了个怪了!为什么官方的Demo怎么能运行啊? 

2.Android-Universal-Image-Loader 会把图片覆盖了,mageLoader的加载缓存!

解决办法:

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. mImageLoader.displayImage("file:///"  
  2.                 + babyPhotoInfo.getBabyPhoto().getPhotoUri(), holder.imageView,  
  3.                 mOptions, new SimpleImageLoadingListener() {  
  4.                     boolean cacheFound;  
  5.   
  6.                     @Override  
  7.                     public void onLoadingStarted(String imageUri, View view) {  
  8.                         List<String> memCache = MemoryCacheUtil  
  9.                                 .findCacheKeysForImageUri(imageUri, ImageLoader  
  10.                                         .getInstance().getMemoryCache());  
  11.                         cacheFound = !memCache.isEmpty();  
  12.                         if (!cacheFound) {  
  13.                             File discCache = DiscCacheUtil.findInCache(  
  14.                                     imageUri, ImageLoader.getInstance()  
  15.                                             .getDiscCache());  
  16.                             if (discCache != null) {  
  17.                                 cacheFound = discCache.exists();  
  18.                             }  
  19.                         }  
  20.   
  21.                     }  
  22.   
  23.                     @Override  
  24.                     public void onLoadingComplete(String imageUri, View view,  
  25.                             Bitmap loadedImage) {  
  26.                         if (cacheFound) {  
  27.                             MemoryCacheUtil.removeFromCache(imageUri,  
  28.                                     ImageLoader.getInstance().getMemoryCache());  
  29.                             DiscCacheUtil.removeFromCache(imageUri, ImageLoader  
  30.                                     .getInstance().getDiscCache());  
  31.   
  32.                             ImageLoader.getInstance().displayImage(imageUri,  
  33.                                     (ImageView) view);  
  34.                         }  
  35.                     }  
  36.                 });  

原来代码:
[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. mImageLoader.displayImage("file:///"  
  2.                 + babyPhotoInfo.getBabyPhoto().getPhotoUri(), holder.imageView,  
  3.                 mOptions, new SimpleImageLoadingListener() {  
  4.                     @Override  
  5.                     public void onLoadingStarted(String imageUri, View view) {}  
  6.   
  7. });  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值