So I’m fairly new to Android dev, and I’ve run into an oddity with using ImageViews. Any pointers or suggestions would be very much welcomed!
I’m setting the bitmaps for my ImageViews dynamically, which is sorta working. Except for that they only sometimes display the image, the rest of the time I get a full color fill with the approximate image color as seen below.

I think they are being scaled properly using this code I got from Android forums, so I don’t think I’m running into memory issues….
public static Bitmap decodeSampledBitmapFromStream(InputStream inputStream, int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(inputStream,null,options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeStream(inputStream,null,options);
}
After many hours of working over the issue, I finally figured out that since I was using an AsyncTask to facilitate the loading of these bitmaps, they were occasionally faster than the main UI thread. This screwed me up when I called
myImageView.getHeight()& width().So here’s the solution that I came up with in the hope that it might help someone else along the way: