ittianyu ittianyu - 1 month ago 5
Android Question

Already resolved

The problem is resolved. Thank you for your help.

Answer

In OnCreate() your view has not yet been created as per your xml parameters. So you have to add addOnGlobalLayoutListener() on your view and you will get your dimensions in that listener once view has been created.

iv.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
    iv.getViewTreeObserver().removeGlobalOnLayoutListener(this);
    System.out.println("imageview width:" + iv.getWidth() + " height:" + iv.getHeight());
   }
});
Comments