0

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

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

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

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

4

1 回答 1

2

在这里你有很好的答案:Android 图像缓存。引述 :

“考虑使用Sergey Tarasevich 的Universal Image Loader 库。它带有:

//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 允许对下载的图像进行详细的缓存管理,具有以下缓存配置:

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.

一个简单的使用示例:

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

于 2013-01-28T16:25:29.363 回答