To measure the width and height of your Imageview at run time
ViewTreeObserver vto = mUserPicImageView.getViewTreeObserver();
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
public boolean onPreDraw() {
if (mImageHeight == 0) {
mImageHeight = mUserPicImageView.getMeasuredHeight();
mImageWidth = mUserPicImageView.getMeasuredWidth();
Log.e("mImageHeight", mImageHeight + "");
}
return true;
}
});
Create image of the above width and height
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap,mImageHeight,mImageWidth, true);
Set the image to ImageView
mUserPicImageView.setImageBitmap(scaledBitmap);