Android图片缓存库使用经验总结
来源:互联网 发布:搜索字幕的软件 编辑:程序博客网 时间:2024/06/01 19:26
1、Android-Universal-Image-Loader
可以高度配置的网络图片缓存库,非常灵活,用户量最多
缓存过期实现:
- File cacheDir = StorageUtils.getCacheDirectory(context); // or any other folder
- MemoryCacheAware<String, Bitmap> memoryCacheCore
- = new LruMemoryCache(4 * 1024 * 1024); // or any other implementation
- MemoryCacheAware<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 缓存图片
- Integer to Roman
- HDU 4355 数轴上的点找使Si^3*Wi最小的和-浮点数三分
- java多线程之 ---- 线程同步
- error LNK2019: 无法解析的外部符号 __imp__CryptBinaryToStringA@20
- c 总结
- Android图片缓存库使用经验总结
- Cookie与Session的区别与联系及生命周期
- 一键安装PPTP服务
- 用JavaScript验证表单
- 图片资源的平铺
- 开始,就现在
- 推特注册相关
- 笔试真题解析 TT-2014 研发笔试题
- HDOJ 1795 The least one(素数打表)