Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stretch image in ImageView

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.

like image 829
developer Avatar asked Oct 18 '13 13:10

developer


People also ask

How do I resize an image in ImageView to keep the aspect ratio?

However, make sure you're setting the image to the ImageView using android:src="..." rather than android:background="..." . src= makes it scale the image maintaining aspect ratio, but background= makes it scale and distort the image to make it fit exactly to the size of the ImageView.

What is adjust view bounds in android?

android:adjustViewBounds—If set to true, the attribute adjusts the bounds of the ImageView control to maintain the aspect ratio of the image displayed through it. android:resizeMode—The resizeMode attribute is used to make a control resizable so we can resize it horizontally, vertically, or around both axes.


1 Answers

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.

like image 91
Enrichman Avatar answered Sep 20 '22 22:09

Enrichman