Schaemelhout
Schaemelhout

Reputation: 705

Android ImageView dynamic ScaleType

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?

Upvotes: 3

Views: 7963

Answers (2)

ACengiz
ACengiz

Reputation: 1315

I am not sure but android:scaleType="fitXY" or android:scaleType="fitCenter" may be the solution of your problem.

Upvotes: 1

Schaemelhout
Schaemelhout

Reputation: 705

I solved this by using the original image from my camera-intent. For some reason, all thumbnail bitmaps were stretched out and in landscape mode.

Upvotes: 0

Related Questions