ittianyu ittianyu - 3 years ago 131
Android Question

Already resolved

The problem is resolved. Thank you for your help.

Answer Source

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() {
public void onGlobalLayout() {
    System.out.println("imageview width:" + iv.getWidth() + " height:" + iv.getHeight());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download