How to get the width and height of an android.widget.ImageView? How to get the width and height of an android.widget.ImageView? android android

How to get the width and height of an android.widget.ImageView?


My answer on this question might help you:

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;    }});

You can then add your image scaling work from within the onPreDraw() method.


I just set this property and now Android OS is taking care of every thing.

android:adjustViewBounds="true"

Use this in your layout.xml where you have planted your ImageView :D


I could get image width and height by its drawable;

int width = imgView.getDrawable().getIntrinsicWidth();int height = imgView.getDrawable().getIntrinsicHeight();