How to auto center cropping ImageView Android?

I made listView images. My goal is for every element of my List to have the same height of 100dp. I am facing the problem that my imageView automatically changes, but does not take up all the space of the parent.

Here is my current result and the result of objectif:

Resized image objectif

Does anyone know which option to add to automatically create a crop center?

+43
android imageview crop
Jul 19 '13 at 13:53 on
source share
4 answers

I’m not sure, I understood correctly. I think this should be one of two things.

In your image view, set the attribute

android:scaleType="fitXY" 

to fully comply with ImageView .

You can choose

 android:scaleType="centerCrop" 

to sow the Center.

+83
Jul 19 '13 at 13:59 on
source share

I know this late, but it might be useful if someone came to this question page using an android: scaleType = "centerCrop" the image is centered, but it is cropped from all sides, so it would be better to use this property instead is fitCenter while using a different property to maintain aspect ratio

 android:adjustViewBounds="true" android:scaleType="fitCenter" 
+20
Aug 11 '15 at 10:48
source share

Do you know about cropping options in ImageView?

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

You simply apply them as an attribute in your XML:

as:

 android:scaleType="centerCrop" 
+7
Jul 19 '13 at 14:01
source share

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

+3
May 7 '14 at 23:59
source share



All Articles