LruCache<String, Bitmap> lruCache;
// 获取应用程序最大可占内存值 int maxMemory = (int) Runtime.getRuntime().maxMemory(); // 设置最大内存的八分之一作为缓存大小 int lruMemory = maxMemory / 8; lruCache = new LruCache<String, Bitmap>(lruMemory) { @Override protected int sizeOf(String key, Bitmap bitmap) { // 返回Bitmap对象所占大小,单位:kb return bitmap.getByteCount(); } };
Bitmap bbg = lruCache.get("tag");lruCache.put("tag", bbg);