Android – Stretch image in ImageView

androidimageview

I have an ImageView that has its height and width set to "fill_parent" with a Relative Layout that has the same values set.Set Image scaleType="fitXY"

Here The XML layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">


<ImageView
    android:id="@+id/imageView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scaleType="fitXY"
    android:src="@drawable/background_image" />


</RelativeLayout>

Fits the width and height but the image is stretched.

Best Answer

That's what fitXY is supposed to do. You can try with centerInside if you don't want to crop your image, or centerCrop if you want to fill all the space (and cropping your image).

Here is a nice list with examples to understand better all the scaleTypes.

Related Topic