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) {}
});
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) {}
});
相关文章推荐
- ImageLoader 俩个比较坑的问题。
- Vector还是ArrayList这是个问题 ――比较Vector和ArrayList的不同
- 利用对手论证法证明中位数问题的比较次数下界
- .Net应用程序发布问题的最新解决方案,感觉比较爽(可桌面、程序中加自己的ICO及卸载等)
- sql语法中时间比较问题
- .Net应用程序发布问题的最新解决方案,感觉比较爽(可桌面、程序中加自己的ICO及卸载等(转贴)
- 提一个比较不知道如何处理的问题?
- PHP在Windows系统下的考虑比较全面的问题!
- 一个论坛发帖的问题,比较菜,希望能得到大虾们的解答!谢谢!!
- 国际化字符串比较的问题
- JAVA中文比较问题的分析和解决
- 关于值类型和引用类型比较的问题
- 关于陈叙远所说的字符串比较问题
- 最近在使用sps类库过程中发现了一个让我比较疑惑的问题(有关items属性的)
- Java中初学者比较爱出错的运算问题
- 用汇编与c解决递归问题之比较
- 一个比较郁闷的问题
- 权限设置问题!(比较着急)
- 解决hh:mm形式时间的比较问题
- 关于ASP+和xml的比较的问题