如何使用NetworkImageView在ListView [英] How to use NetworkImageView in a ListView
问题描述
我在Android的新的和我被困的东西。
我有一个LisView,我试图下载使用NetworkImageView图像,但我不能设法去做。
我有这个在onCreate方法:
networkImageView =(NetworkImageView)findViewById(R.id.thumbImageUrl);
mRequestQueue = Volley.newRequestQueue(本);
ImageLoader的=新ImageLoader的(mRequestQueue,新BitmapLruCache(BitmapLruCache.getDefaultLruCacheSize()));networkImageView.setImageUrl(IMAGE_URL,ImageLoader的);
但它不工作,我不知道为什么。
谁能告诉我该怎么办呢?我觉得我没有理解太清楚如何使用NetworkImageView。
PS:我BitmapLruCache.java
公共类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,位图);
}}
如果你想图像加载到ListView的项目,你应该这样做在适配器的<一个href=\"http://developer.android.com/reference/android/widget/Adapter.html#getView%28int,%20android.view.View,%20android.view.ViewGroup%29\"相对=nofollow> getView()方法。勾选此<一个href=\"https://github.com/ogrebgr/android_volley_examples/blob/master/src/com/github/volley_examples/misc/PicasaArrayAdapter.java\"相对=nofollow>例如的。它应该帮助你。
I am new in Android and I got stuck on something. I have a LisView and I am trying to download images using NetworkImageView, but I can't manage to do it.
I have this in onCreate method:
networkImageView = (NetworkImageView) findViewById(R.id.thumbImageUrl);
mRequestQueue = Volley.newRequestQueue(this);
imageLoader = new ImageLoader(mRequestQueue, new BitmapLruCache(BitmapLruCache.getDefaultLruCacheSize()));
networkImageView.setImageUrl(IMAGE_URL, imageLoader);
but it doesn't work and I don't know why.
Can anybody tell me how to do it? I think I didn't understood too well how to use NetworkImageView.
PS: my BitmapLruCache.java
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);
}}
If you are trying to load image into ListView's item, you should do it in the Adapter's getView() method. Check this example. It should help you.
这篇关于如何使用NetworkImageView在ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!