I'm trying to get the width and height of an imageView after the screen is rotated but it always returns 0 Note: onWindowFocusChanged doesn't get called after rotation because i handle the rotation manually. Also when i tried this code
ViewTreeObserver vto = mImgView.getViewTreeObserver();
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
public boolean onPreDraw() {
mImgView.getViewTreeObserver().removeOnPreDrawListener(this);
viewWidth = mImgView.getWidth();
Log.e("Width =",viewWidth +"");
return true;
}
});
it get called twice and returns different values one of them is correct !! My Image view display code is as follows
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Configuration config=getResources().getConfiguration();
if(config.orientation == Configuration.ORIENTATION_PORTRAIT)
{
setContentView(R.layout.quran_display_act);
mImgtView = (ImageView) findViewById(R.id.rightImg_view);
mImgtView.setImageBitmap(bitmap);
//TODO hereee
float viewWidth = mImgtView.getWidth();
...
}