I have an Android Activity with an ImageView. I put the ScaleType of the imageview on CENTER_CROP, so the image itself would not stretch.
<ImageView
android:id="@+id/imgView"
android:layout_width="fill_parent"
android:layout_height="135dp"
android:scaleType="centerCrop"
android:src="@drawable/capture" />
The image that's loaded at first does what I expect, it's cropped to the center, filling the whole ImageView.
Now, if I set the image of the ImageView programatically,
imgView.setImageBitmap(b)
imgView.setScaleType(ImageView.ScaleType.CENTER_CROP);
The picture gets displayed, but it's completely stretched out to fill the ImageView... AdjustViewBounds has no effect what so ever, nor does anything else.
The difference between the working XML and the not-working java code is that in XML I'm putting the image as a resource, and the code is putting a Drawable in the ImageView from a web-service...
Does anyone have an idea to the solution?
I am not sure but android:scaleType="fitXY" or android:scaleType="fitCenter" may be the solution of your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With