Android Volley ImageLoader - BitmapLruCache parameter?

后端 未结 5 2010
迷失自我
迷失自我 2020-12-01 01:05

I am having trouble implementing Image cache using the new Volley library. In the presentation, code look like this

mRequestQueue = Volley.newRequestQueue(co         


        
5条回答
  •  鱼传尺愫
    2020-12-01 01:23

    this is comes in new API to handle the OOM

    public class BitmapMemCache extends LruCache implements ImageCache {
    
        public BitmapMemCache() {
            this((int) (Runtime.getRuntime().maxMemory() / 1024) / 8);
        }
    
        public BitmapMemCache(int sizeInKiloBytes) {
            super(sizeInKiloBytes);
        }
    
        @Override
        protected int sizeOf(String key, Bitmap bitmap) {
            int size = bitmap.getByteCount() / 1024;
            return size;
        }
    
        public boolean contains(String key) {
            return get(key) != null;
        }
    
        public Bitmap getBitmap(String key) {
            Bitmap bitmap = get(key);
            return bitmap;
        }
    
        public void putBitmap(String url, Bitmap bitmap) {
            put(url, bitmap);
        }
    }
    

提交回复
热议问题