我正在使用AdapterViewFlipper,它显示来自资源的图像但是当我尝试从url加载动态图像时它没有显示任何内容。
//工作呢
holder.flipper_image_view.setImageResource(R.drawable.app_icon_small);
//无法正常工作
imageLoader.loadImage(imageUrl.trim(),
options, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String s, View view) {
}
@Override
public void onLoadingFailed(String s, View view, FailReason failReason) {
}
@Override
public void onLoadingComplete(String s, View view, Bitmap bitmap) {
holder.flipper_image_view.setImageBitmap(bitmap);
}
@Override
public void onLoadingCancelled(String s, View view) {
}
});
我已经检查过网址上的图像,并且在浏览器中打开它也很容易使用简单的Imageview。请建议。
答案 0 :(得分:0)
试试这个,
NetworkImageView networkImageView = (NetworkImageView) findViewById(R.id.thumbImageUrl);
RequestQueue mRequestQueue = Volley.newRequestQueue(this);
ImageLoader imageLoader = new ImageLoader(mRequestQueue, new BitmapLruCache(BitmapLruCache.getDefaultLruCacheSize()));
networkImageView.setImageUrl(IMAGE_URL, imageLoader);
这是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);
}}