2013.04.03——— android 图片缓存之二LruCache介绍
16lz
2021-01-23
2013.04.03——— android 图片缓存之二LruCache介绍
参考:http://blog.csdn.net/linghu_java/article/details/8574102
android已经提供了一个lru的缓存数据结构,所以我们已不需要用LinkedhashMap来模拟了
参考:http://blog.csdn.net/linghu_java/article/details/8574102
android已经提供了一个lru的缓存数据结构,所以我们已不需要用LinkedhashMap来模拟了
int memClass = ((ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass(); int cacheSize = 1024 * 1024 * memClass / 4; //系统可用内存的1/4 mLruCache = new LruCache<String, Bitmap>(cacheSize) { @Override protected int sizeOf(String key, Bitmap value) { if (value != null) return value.getRowBytes() * value.getHeight(); else return 0; } @Override protected void entryRemoved(boolean evicted, String key, Bitmap oldValue, Bitmap newValue) { if (oldValue != null) // 缓存容量满的时候,会根据LRU算法把最近没有被使用的图片转入此软引用缓存 mSoftCache.put(key, new SoftReference<Bitmap>(oldValue)); } };
更多相关文章
- Android利用Matrix简单处理图片
- android带有文字的图片按钮的两种实现方式
- 演化理解 Android 异步加载图片
- Android布局的一些属性和开关、创建log图片
- Android WebView实现选择本地图片拍照功能
- 很实用的android压缩图片的算法
- Android Studio 清理缓存clean project与invalidate caches
- android imageView 图片显示方式属性