In my code I have an Image View in my XML layout and I keep changing the source image for this in my code. Now I want to know the width and height of the generated image each time.
I tried using getWidth(), getHeight(), getMeasuredWidth(), and getMeasuredHeight(), but they all return 0.
How can I get this?
Where you calling
getWidth()andgetHeight()on ImageView? If you calling fromonCreate()in activity, it won’t work. You need to wait for activity window to attached and then callgetWidth() and getHeight()on ImageView. You can try callinggetWidth() and getHeight()fromonWindowFocusChanged()method of your activity.