Android的凌空ImageLoader的 - BitmapLruCache参数? [英] Android Volley ImageLoader - BitmapLruCache parameter?

查看:208
本文介绍了Android的凌空ImageLoader的 - BitmapLruCache参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在用的是新的排枪库有执行困难的图像缓存。在presentation,code这个样子的。

  mRequestQueue = Volley.newRequestQueue(上下文);
mImageLoader =新ImageLoader的(mRequestQueue,新BitmapLruCache());
 

该BitmapLruCache显然是不包含在工具包。任何想法如何实现它或点我的一些资源?

http://www.youtube.com/watch?v=yhv8l9F44qo @ 14:38

谢谢!

解决方案

 进口android.graphics.Bitmap;
进口android.support.v4.util.LruCache;

公共类BitmapLruCache扩展LruCache<字符串,位图>实现ImageCache {
    公共静态INT getDefaultLruCacheSize(){
        最终诠释maxMemory =(INT)(调用Runtime.getRuntime()maxMemory()/ 1024);
        最终诠释CACHESIZE = maxMemory / 8;

        返回CACHESIZE;
    }

    公共BitmapLruCache(){
        这个(getDefaultLruCacheSize());
    }

    公共BitmapLruCache(INT sizeInKiloBytes){
        超(sizeInKiloBytes);
    }

    @覆盖
    保护INT整型尺寸(字符串键,位图值){
        返回value.getRowBytes()* value.getHeight()/ 1024;
    }

    @覆盖
    公共位图getBitmap(字符串URL){
        得到的回报(URL);
    }

    @覆盖
    公共无效putBitmap(字符串URL,位图位图){
        把(URL,位图);
    }
}
 

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

mRequestQueue = Volley.newRequestQueue(context);
mImageLoader = new ImageLoader(mRequestQueue, new BitmapLruCache());

The BitmapLruCache is obviously not included in the toolkit. Any idea how to implement it or point me to some resources?

http://www.youtube.com/watch?v=yhv8l9F44qo @14:38

Thanks!

解决方案

import android.graphics.Bitmap;
import android.support.v4.util.LruCache;

public class BitmapLruCache extends LruCache<String, Bitmap> 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);
    }
}

这篇关于Android的凌空ImageLoader的 - BitmapLruCache参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆