If some ImageView
s are related to GridView
or ListView
, and we want to display some images on screen, it often happens the value of an image's width and height are zero(0), so it occurs Exception when we pass this arguments to calculate the compressed Bitmap, I review some frameworks but it's still a problem for me.I want to obtain some kernel solutions to solve this problem. what should I do when the ImageView
's width and height is 0.Any help is much appreciated.
public void loadImage(final ImageView imageView, final String imageUrl){
mExecutor.execute(new PriorityRunnable(mThreadsCount) {
@Override
public void doSomething() {
while(!mExecutor.isPause()){
if(imageView != null && imageView.getTag().equals(imageUrl)){
mImageCache.loadImage(imageView, imageUrl);
}
}
}
});
}
public void loadImage(ImageView imageView, String imageUrl){
//readFromMemoryCache
Bitmap bitmap = getBitmap(imageUrl);
if(bitmap != null){
mImageView = imageView;
mBitmap = bitmap;
mHandler.sendEmptyMessage(DISPLAY_IMAGE);
return;
}
int width = imageView.getWidth();
int height = imageView.getHeight();
//because width = 0, so it doesn't do anything, only return
if(width == 0 || height == 0){
return;
}
//load from http or disk
bitmap = getBitmap(imageUrl, width, height);
if(bitmap != null){
mImageView = imageView;
mBitmap = bitmap;
mHandler.sendEmptyMessage(DISPLAY_IMAGE);
}
}