您的位置:首页 > 其它

ImageLoader 俩个比较坑的问题。

2014-10-10 23:25 218 查看
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 plaincopy





mImageLoader.displayImage("file:///"
+ babyPhotoInfo.getBabyPhoto().getPhotoUri(), holder.imageView,
mOptions, new SimpleImageLoadingListener() {
boolean cacheFound;

@Override
public void onLoadingStarted(String imageUri, View view) {
List<String> memCache = MemoryCacheUtil
.findCacheKeysForImageUri(imageUri, ImageLoader
.getInstance().getMemoryCache());
cacheFound = !memCache.isEmpty();
if (!cacheFound) {
File discCache = DiscCacheUtil.findInCache(
imageUri, ImageLoader.getInstance()
.getDiscCache());
if (discCache != null) {
cacheFound = discCache.exists();
}
}

}

@Override
public void onLoadingComplete(String imageUri, View view,
Bitmap loadedImage) {
if (cacheFound) {
MemoryCacheUtil.removeFromCache(imageUri,
ImageLoader.getInstance().getMemoryCache());
DiscCacheUtil.removeFromCache(imageUri, ImageLoader
.getInstance().getDiscCache());

ImageLoader.getInstance().displayImage(imageUri,
(ImageView) view);
}
}
});

原来代码:

[html]
view plaincopy





mImageLoader.displayImage("file:///"
+ babyPhotoInfo.getBabyPhoto().getPhotoUri(), holder.imageView,
mOptions, new SimpleImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {}

});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: