Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to auto center crop ImageView Android?

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?

like image 554
lopez.mikhael Avatar asked Jul 19 '13 13:07

lopez.mikhael


2 Answers

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.

like image 57
Naresh Avatar answered Sep 29 '22 07:09

Naresh


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" 
like image 32
Mehroz Munir Avatar answered Sep 29 '22 07:09

Mehroz Munir