您可以嘗試如下的代碼片斷..
ImageView image = ImageView.class.cast(layout.findViewById(R.id...));
String url = "..."; // URL of the image
mImageLoader.get(url, new ImageListener() {
public void onErrorResponse(VolleyError arg0) {
image.setImageResource(R.drawable.icon_error); // set an error image if the download fails
}
public void onResponse(ImageContainer response, boolean arg1) {
if (response.getBitmap() != null) {
image.startAnimation(AnimationUtils.loadAnimation(container.getContext(), android.R.anim.fade_in));
image.setImageBitmap(response.getBitmap());
} else
image.setImageResource(R.drawable.icon_loading); // set the loading image while the download is in progress
}
});
可以如下創建mImageLoader實例來實現緩存
mRequestQueue = Volley.newRequestQueue(context);
mImageLoader = new ImageLoader(mRequestQueue, new ImageLoader.ImageCache() {
private final LruCache<String, Bitmap> mCache = new LruCache<String, Bitmap>(10);
public void putBitmap(String url, Bitmap bitmap) {
mCache.put(url, bitmap);
}
public Bitmap getBitmap(String url) {
return mCache.get(url);
}
});'
你試過繼承'NetworkImageView'並添加接口圖像loades? – user2558461
什麼是imageView1?定義在哪裏? –