Image resizing to Imageview

I look at MANY questions on Stackoverflow and tried many workarounds, but it still didn't work.

What I want to achieve:

enter image description hereenter image description here

But I achieve this:

enter image description here

This is my current xml code:

<ImageView android:id="@+id/image" android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_below="@+id/text" android:layout_gravity="center" android:adjustViewBounds="true" android:scaleType="centerInside" android:src="@drawable/ic_action_search" /> 
+8
android android-imageview
source share
4 answers

The best way to achieve this is to scale the image (bitmap) with a matrix.

An alternative is to use a library that I previously created that does this for you:

https://github.com/laurencedawson/ZoomableImageView

This automatically scales the image to fit the screen and also zooms in.

+3
source share

add

 <ImageView android:id="@+id/image" android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_below="@+id/text" android:layout_gravity="center" android:adjustViewBounds="true" android:scaleType="fitXY" android:src="@drawable/ic_action_search" /> 
+2
source share

CenterInside, resize the image according to the viewing parameters and its resolutions. So, if the image has a size of 300 * 450, and we set this image to a figurative image of a scale of the type centerinside with dimensions 200 * 400, then the image size will be 200 * 300, in accordance with the target sizes, so scaling it down is 200 minimum width and height. I hope I'm clear enough. In cases where you need to set the exact size, use FItXY, as suggested by Adeel.

+1
source share

Do you want to do this inside the XML file correctly?

 <ImageView android:layout_width="size of image (in density pixels)" android:layout_height="size of image (in density pixels)" /> 

for example:

 <ImageView android:layout_width="60dp" android:layout_height="60dp" /> 
0
source share

All Articles