NoobMe
NoobMe

Reputation: 544

ImageView fit without stretching the image

is it possible that my ImageView will fit to all screen sizes without the image look stretched?

i tried all scale types changing it to background and src with fill_parent > wrap_content

but still. if the image is not smaller it just looks stretched..

example:

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scaleType="centerInside"
    android:adjustViewBounds="true"
    android:background="@drawable/background" />

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scaleType="fitXY"
    android:adjustViewBounds="true"
    android:background="@drawable/background" />

these 2 fits the width but the image is stretched.. but when i change it to src the image is just centered and small.

Upvotes: 20

Views: 54324

Answers (2)

Juned Khatri
Juned Khatri

Reputation: 751

You can do it by just adding just one attributes to ImageView

android:adjustViewBounds="true"

Upvotes: 13

MH.
MH.

Reputation: 45493

There is no built-in scale type that allows the ImageView to automatically upscale the image and keep its aspect ratio intact. The only scale type that does upscaling is fitXY, which won't respect the aspect ratio, as you found out yourself too.

That being said, this topic has already been visited more than once. Have a look at some of the proposed suggestions for similar questions:

I'm sure'll be heaps more, so it might worth using the search box at the top.

Upvotes: 32

Related Questions