How to get the width and height of an Image View in android?

Where you calling getWidth() and getHeight() on ImageView? If you calling from onCreate() in activity, it won’t work. You need to wait for activity window to attached and then call getWidth() and getHeight() on ImageView. You can try calling getWidth() and getHeight() from onWindowFocusChanged() method of your activity.

@Override
public void onWindowFocusChanged(boolean hasFocus){
    int width=imageView.getWidth();
    int height=imageView.getHeight();
}

Leave a Comment