Question: 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?

Answer: 
try this

```
 ImageView iv=(ImageView)findViewById(R.id.image);
 ViewTreeObserver vto = iv.getViewTreeObserver();
    vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        public boolean onPreDraw() {
           finalHeight = iv.getMeasuredHeight();
           finalWidth = iv.getMeasuredWidth();
           Log.e("hilength","Height: " + finalHeight + " Width: " + finalWidth);
            return true;
        }
    });

```
if you set ImageView a drawable, and the ImageView's height and width type is WRAP\_CONTENT, you can get the ImageView's height and width by this even you calling from `onCreate()`

```
int height = imageView.getDrawable().getIntrinsicHeight();
int width = imageView.getDrawable().getIntrinsicWidth();

```