Android图片缓存库使用经验总结
来源:互联网 发布:软件需求开发流程 编辑:程序博客网 时间:2024/06/18 11:12
1、Android-Universal-Image-Loader
可以高度配置的网络图片缓存库,非常灵活,用户量最多
缓存过期实现:
File cacheDir = StorageUtils.getCacheDirectory(context); // or any other folderMemoryCacheAware<String, Bitmap> memoryCacheCore = new LruMemoryCache(4 * 1024 * 1024); // or any other implementationMemoryCacheAware<String, Bitmap> memoryCache = new LimitedAgeMemoryCache<String, Bitmap>(memoryCacheCore, 15 * 60);DiscCacheAware discCache = new LimitedAgeDiscCache(cacheDir, 15 * 60);ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context) .memoryCache(memoryCache) .discCache(discCache) ... .build();
If you use "limited age" memory cache or disc cache then bitmap or image file will be deleted from cache after timeout (actually they will be deleted during search in cache). Logic is following:
- Search bitmap in memory cache
- needed bitmap is there
- bitmap was added to cache more than specified time ago
- delete it from memory cache, go to step 2
- bitmap was added to cache recently
- get the bitmap, display it. End.
- bitmap was added to cache more than specified time ago
- no needed bitmap in cache, go to step 2
- needed bitmap is there
- Search image file in disc cache
- needed image is there
- image was added to cache more than specified time ago
- delete it from disc cache, go to step 3
- image was added to cache recently
- decode image to bitmap, display it. End.
- image was added to cache more than specified time ago
- no needed image in cache, go to step 3
- needed image is there
- Download image
Don't forget enable caching (in display options, DisplayImageOptions
).
针对同一图片地址,图片会变的情况,平滑替换过期图片的实现:
方法1:重写LimitedAgeDiscCache、LimitedAgeMemoryCache的get方法
方法2:增加判断缓存是否过期的接口,如果过期则通过下载回调监听的方式更新UI。
2、 androidQuery
链式调用,有自定义图片载入效果
3、Picasso
功能单一,没有缓存过期,同androidQuery一样链式调用,载入本地文件速度慢(没有生成thumbnails)。这有一篇老外的对比:http://stackoverflow.com/questions/19995007/local-image-caching-solution-for-android-square-picasso-vs-universal-image-load
4、android-smart-image-view
古董了,功能老掉牙了,不要用了
0 0
- Android图片缓存库使用经验总结
- Android图片缓存库使用经验总结
- Android使用 LruCache 缓存图片
- Android使用 LruCache 缓存图片
- Android使用 LruCache 缓存图片
- Android使用 LruCache 缓存图片
- Android使用 LruCache 缓存图片
- Android使用 LruCache 缓存图片
- Android使用 LruCache 缓存图片
- Android使用 LruCache 缓存图片
- Android使用 LruCache 缓存图片
- Android使用 LruCache 缓存图片
- Android使用 LruCache 缓存图片
- Android使用 LruCache 缓存图片
- Android使用 LruCache 缓存图片
- Android使用 LruCache 缓存图片
- Android使用 LruCache 缓存图片
- Android使用 LruCache 缓存图片
- test3
- Listview异步加载图片之优化篇
- 《Apache HttpClient 4.3开发指南》
- perl发送邮件中文乱码解决
- HttpClient
- Android图片缓存库使用经验总结
- 海,朋友别睡了,如果你认为做梦就能梦想成真的话,说明你太天真了
- jquery mobile + iscroll + iscrollview 开发滚动翻页功能
- 监控SQL SERVER的运行状况-常用检测语句
- 打开或取消Mac隐藏目录
- UI自动化测试工具White简介以及使用经验总结
- 网络编程 (1)
- 网络编程 (2)
- js常用字符串检测方法 (正则表达式)