这是我目前的代码:
private void networkImage(){
String url = "http://example.com/profilePictures/"+username+".jpg";
networkImageView = (NetworkImageView) findViewById(R.id.IBProfilePicture);
networkImageView.setOnClickListener(this);
RequestQueue networkQueue = Volley.newRequestQueue(getApplicationContext());
networkQueue.getCache().remove(url);
networkQueue.getCache().clear();
ImageLoader networkImageLoader = new ImageLoader(networkQueue, new ImageLoader.ImageCache() {
@Override
public Bitmap getBitmap(String url) {
return null;
}
@Override
public void putBitmap(String url, Bitmap bitmap) {
}
});
networkImageView.setImageUrl(url,networkImageLoader);
}
答案 0 :(得分:3)
试试这个解决方案:
private void networkImage(){
String url = "http://example.com/profilePictures/"+username+".jpg";
networkImageView = (NetworkImageView) findViewById(R.id.IBProfilePicture);
networkImageView.setOnClickListener(this);
RequestQueue networkQueue = Volley.newRequestQueue(getApplicationContext());
ImageLoader networkImageLoader = new ImageLoader(networkQueue, new ImageLoader.ImageCache() {
@Override
public Bitmap getBitmap(String url) {
return null;
}
@Override
public void putBitmap(String url, Bitmap bitmap) {
}
});
networkImageView.setImageUrl(url+"?time="+System.currentTimeMillis(),networkImageLoader);
}
答案 1 :(得分:3)
request.setShouldCache(false)
为请求禁用缓存。对于方法2,您可以通过覆盖ImageLoader.makeImageRequest()
;
public class NoCacheImageLoader extends ImageLoader {
public NoCacheImageLoader(RequestQueue queue, ImageCache imageCache) {
super(queue, imageCache);
}
@Override
protected Request<Bitmap> makeImageRequest(String requestUrl, int maxWidth, int maxHeight, ImageView.ScaleType scaleType, String cacheKey) {
Request<Bitmap> request = super.makeImageRequest(requestUrl, maxWidth, maxHeight, scaleType, cacheKey);
// key method
request.setShouldCache(false);
return request;
}
}
然后使用NoCacheImageLoader
代替ImageLoader
。现在它不会将图像缓存到磁盘中。
顺便说一句,您仍应将时间戳添加到网址,因为如果网址相同,NetworkImageView
将无法再次加载图片。