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: 
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();

```
try this code 

```
int finalHeight, finalWidth;
final ImageView iv = (ImageView)findViewById(R.id.scaled_image);
final TextView tv = (TextView)findViewById(R.id.size_label);
ViewTreeObserver vto = iv.getViewTreeObserver();
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
    public boolean onPreDraw() {
        iv.getViewTreeObserver().removeOnPreDrawListener(this);
        finalHeight = iv.getMeasuredHeight();
        finalWidth = iv.getMeasuredWidth();
        tv.setText("Height: " + finalHeight + " Width: " + finalWidth);
        return true;
    }
});

```

it's really working...