2013.04.03——— android 图片缓存之二LruCache介绍
参考: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));            }        };


更多相关文章

  1. Android利用Matrix简单处理图片
  2. android带有文字的图片按钮的两种实现方式
  3. 演化理解 Android 异步加载图片
  4. Android布局的一些属性和开关、创建log图片
  5. Android WebView实现选择本地图片拍照功能
  6. 很实用的android压缩图片的算法
  7. Android Studio 清理缓存clean project与invalidate caches
  8. android imageView 图片显示方式属性

随机推荐

  1. Android开发初步之Activity与Intent
  2. Android 最火快速开发框架AndroidAnnotat
  3. android应用安全――代码安全(android代码
  4. android之绕Y轴旋转
  5. android中handler案例
  6. Android(安卓)Binder Mechanism (2) --
  7. 招聘android架构师(北京)
  8. 用Lazarus编译Android工程
  9. 北京友好互动科技发展有限公司招聘ios、c
  10. Android中几种图像特效处理的集锦!!