How to auto center crop ImageView Android?

AndroidImageviewCrop

Android Problem Overview


I made a listView images. My goal that each item of my listView have the same height of 100dp. I encounter a problem that my imageView is resized automatically, but does not take the entire space of the parent.

Here is my current result and objectif result :

Resized Image objectif

Does anyone know the option to add to make crop center automatically?

Android Solutions


Solution 1 - Android

I am not sure if I understood correctly. It must be either of the two, that you want, I guess.

In your image view set the attribute

android:scaleType="fitXY"

to fit the ImageView completely.

You can choose

android:scaleType="centerCrop"

to crop Center.

Solution 2 - Android

i know it's late but maybe it would be helpful for someone coming on this question page by using android:scaleType="centerCrop" image is centered but it is cropped from all sides so it would be better to use this property instead that is fitCenter and with this use another property too to maintain the aspect ratio

android:adjustViewBounds="true"            
android:scaleType="fitCenter"

Solution 3 - Android

Are you aware of the cropping options on ImageView?

http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

You will just apply these as an attribute in your XML:

like:

android:scaleType="centerCrop"  

Solution 4 - Android

in java: imageView.setScaleType(ScaleType.FIT_XY);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionlopez.mikhaelView Question on Stackoverflow
Solution 1 - AndroidNareshView Answer on Stackoverflow
Solution 2 - AndroidMehroz MunirView Answer on Stackoverflow
Solution 3 - AndroidBoogerView Answer on Stackoverflow
Solution 4 - AndroidLevi SaturninoView Answer on Stackoverflow