首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >缓存磁盘镜像

缓存磁盘镜像
EN

Stack Overflow用户
提问于 2013-01-29 00:21:29
回答 1查看 4.9K关注 0票数 0

我尝试使用磁盘缓存(而不是内存缓存),因此我从urls下载图像并将其放在网格视图中。我只想下载我的图片一次。

我在谷歌网站http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html上找到了这个例子(bitmapFun

我发现这个例子有点复杂。util包中有很多对象(AsyncTask、DiskLruCache、ImageCache、ImageFetcher、ImageResizer、ImageWorker、Utils)

有没有一种方法或教程可以说明如何在不使用所有这些对象的情况下使用磁盘Lru缓存。我不想调整图像的大小,也不能删除ImageResizer类。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-29 00:25:29

这里你有一个很好的答案:Android image caching。引用:

“考虑使用谢尔盖·塔拉塞维奇的Universal Image Loader library。它附带:

代码语言:javascript
复制
//Multithread image loading. It lets you can define the thread pool size
//Image caching in memory, on device's file sytem and SD card.
//Possibility to listen to loading progress and loading events

Universal Image Loader允许对下载的图像进行详细的缓存管理,具有以下缓存配置:

代码语言:javascript
复制
UsingFreqLimitedMemoryCache: //The least frequently used bitmap is deleted when the cache size limit is exceeded.
LRULimitedMemoryCache: //The least recently used bitmap is deleted when the cache size limit is exceeded.
FIFOLimitedMemoryCache: //The FIFO rule is used for deletion when the cache size limit is exceeded.
LargestLimitedMemoryCache: //The largest bitmap is deleted when the cache size limit is exceeded.
LimitedAgeMemoryCache: //The Cached object is deleted when its age exceeds defined value.
WeakMemoryCache: //A memory cache with only weak references to bitmaps.

一个简单的用法示例:

代码语言:javascript
复制
ImageView imageView = groupView.findViewById(R.id.imageView);
String imageUrl = "http://domain.com/image.png"; 

ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration.createDefault(context));
imageLoader.displayImage(imageUrl, imageView);

此示例使用默认UsingFreqLimitedMemoryCache

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14566439

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档