How to auto center crop ImageView Android?

2019-01-21 16:38发布

问题:

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 :

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

回答1:

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.



回答2:

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"


回答3:

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"  


回答4:

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