Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Need help cropping instead of resizing an imageview extending beyond parent layout

Tags:

android

I have a relative layout with some ImageViews that sometimes extend beyond the layout's boundaries. When this happens the ImageViews get resized so they become smaller instead of extend out of bounds. I want them to display normally and just get cropped.

I think there is some kind of boolean to do that, but I can't find it in the API. I thought it might be clipChildren under ViewGroups, but setting that to false or true seems to do nothing. Anyone help is appreciated.

like image 397
Don Avatar asked Jan 15 '11 23:01

Don


People also ask

Which attribute is important for ImageView other than width and height *?

Bookmark this question.

How do I adjust photos on Android?

Tap the image you want to adjust. You can adjust the size of an image or rotate it: Resize: Touch and drag the squares along the edges. Rotate: Touch and drag the circle attached to the image.


1 Answers

A little bit late but have you tried this code in your xml?

   <ImageView
 android:scaleType="centerCrop"
 android:id="@+id/imageView"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent" />

The key is in scaleType. It keeps the aspect ratio of your image cropping it to the bounds of layout.

like image 57
Racker Avatar answered Sep 28 '22 11:09

Racker