LRUCache写法

论坛 期权论坛 脚本     
匿名技术用户   2020-12-30 23:11   63   0

import android.support.v4.util.LruCache;


public class ImageCache {

private ImageCache() {
// use 1/8 of available heap size
cache = new LruCache<String, Bitmap>((int) (Runtime.getRuntime().maxMemory() / 8)) {
@Override
protected int sizeOf(String key, Bitmap value) {
return value.getRowBytes() * value.getHeight();
}
};
}


private static ImageCache imageCache = null;


public static synchronized ImageCache getInstance() {
if (imageCache == null) {
imageCache = new ImageCache();
}
return imageCache;


}
private LruCache<String, Bitmap> cache = null;

/**
* put bitmap to image cache
* @param key
* @param value
* @return the puts bitmap
*/
public Bitmap put(String key, Bitmap value){
return cache.put(key, value);
}

/**
* return the bitmap
* @param key
* @return
*/
public Bitmap get(String key){
return cache.get(key);
}
}
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP