I have a launch screen imageview in my application. I am converting png file bundled with my application to bitmap after scaling it as png is greater resolution. I am doing decoing and scaling down in callback function of that imageview when it is about to draw. I need the bitmap to fill entire screen. But Sometimes it is not getting drawn as It is getting width and height of the view as 0. It occurs sometime only. I think this is not the right way of doing it. Please suggest me best solution.
<com.example.myImageView
android:id="@+id/ovation_background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="@string/background_screen"
android:background="@color/black"/>
In Activity onCreate function:
mImageView.getMeasuredWidth() and mImageView.getMeasuredHeight() is coming as 0 sometimes.
ViewTreeObserver vtoBackgroundView = mImageView.getViewTreeObserver();
vtoBackgroundView.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
Bitmap bitmap = decodeSampledBitmapFromResource
(getResources(), R.drawable.launch_screen,
**mImageView.getMeasuredWidth()**,
**mImageView.getMeasuredHeight()**);
if ( bitmap != null )
{
mImageView.setBackgroundBitmap(bitmap);
}
ViewTreeObserver obs2 = mImageView.getViewTreeObserver();
obs2.removeOnPreDrawListener(this);
return true;
}
});