1. 程式人生 > >Android 圖片三級快取

Android 圖片三級快取

開發十年,就只剩下這套架構體系了! >>>   

public class MemoryCache {

    private LruCache<String, Bitmap> lruCache;

    public MemoryCache() {

        lruCache = new LruCache<String, Bitmap>((int)(Runtime.getRuntime().maxMemory()/8)) {

            protected int sizeOf(String key, Bitmap bitmap) {

                return bitmap.getByteCount();

            }

        }

    }

    public void put(String key, Bitmap bitmap) {

        lruCache.put(key, bitmap);

    }

    public Bitmap get(String key) {

        lruCache.get(key);

  &n