Android Volley ImageLoader - BitmapLruCache 参数? [英] Android Volley ImageLoader - BitmapLruCache parameter?
本文介绍了Android Volley ImageLoader - BitmapLruCache 参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用新的 Volley 库实现图像缓存时遇到了问题.在演示文稿中,代码如下所示
mRequestQueue = Volley.newRequestQueue(context);mImageLoader = new ImageLoader(mRequestQueue, new BitmapLruCache());
BitmapLruCache 显然没有包含在工具包中.知道如何实施它或向我指出一些资源吗?
http://www.youtube.com/watch?v=yhv8l9F44qo @14:38>
谢谢!
解决方案
import android.graphics.Bitmap;导入 android.support.v4.util.LruCache;公共类 BitmapLruCache 扩展了 LruCache实现 ImageCache {公共静态 int getDefaultLruCacheSize() {最终 int maxMemory = (int) (Runtime.getRuntime().maxMemory()/1024);最终 int cacheSize = maxMemory/8;返回缓存大小;}公共 BitmapLruCache() {这(getDefaultLruCacheSize());}公共 BitmapLruCache(int sizeInKiloBytes) {超级(sizeInKiloBytes);}@覆盖protected int sizeOf(String key, Bitmap value) {返回 value.getRowBytes() * value.getHeight()/1024;}@覆盖公共位图 getBitmap(String url) {返回获取(网址);}@覆盖public void putBitmap(String url, Bitmap bitmap) {放置(网址,位图);}}
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 Volley ImageLoader - BitmapLruCache 参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文