开发者

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

开发者 https://www.devze.com 2023-02-04 18:10 出处:网络
I have a relative layout with some ImageViews that sometimes extend beyond the layout\'s boundaries. When this happens the ImageView开发者_运维问答s get resized so they become smaller instead of exten

I have a relative layout with some ImageViews that sometimes extend beyond the layout's boundaries. When this happens the ImageView开发者_运维问答s 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消