Android Volley ImageLoader - BitmapLruCache parameter?

后端 未结 5 2002
迷失自我
迷失自我 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条回答
  •  -上瘾入骨i
    2020-12-01 01:38

    import android.graphics.Bitmap;
    import android.support.v4.util.LruCache;
    
    public class BitmapLruCache extends LruCache implements ImageCache {
        public static int getDefaultLruCacheSize() {
            final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
            final int cacheSize = maxMemory / 8;
    
            return cacheSize;
        }
    
        public BitmapLruCache() {
            this(getDefaultLruCacheSize());
        }
    
        public BitmapLruCache(int sizeInKiloBytes) {
            super(sizeInKiloBytes);
        }
    
        @Override
        protected int sizeOf(String key, Bitmap value) {
            return value.getRowBytes() * value.getHeight() / 1024;
        }
    
        @Override
        public Bitmap getBitmap(String url) {
            return get(url);
        }
    
        @Override
        public void putBitmap(String url, Bitmap bitmap) {
            put(url, bitmap);
        }
    }
    

提交回复
热议问题