I have a square ImageView
which displays pictures of varying dimensions. I want to always maintain the original aspect ratio of the pictures and have no margin around the image (so that the image takes up the whole ImageView). For this, I am using the centerCrop
scaleType on the ImageView
. However, I want to make it so that if the top and bottom of the image are cut off (i.e.: the image is taller than it is wide), the image gets pulled towards the bottom of the container. So instead of having equal amounts of pixels cropped at the top and bottom, the image is flush with the top and sides of the ImageView
and the bottom of the image has twice as much cropped off. Is this possible in xml, if not, is there a java solution?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
You probably can't do this in layout. But it's possible with a piece of code like this:
Note that if your
ImageView
has predefined size (likely it has) then you need to put this size todimen
resources and the code will be even simpler:See also:
You won't be able to do that with a regular
ImageView
and it's properties in xml. You can accomplish that with a properscaleType
Matrix
, but tbh writing it is a pain in the ass. I'd suggest you use a respected library that can handle this easily. For exampleCropImageView
.