Android ImageView topCrop / bottomCrop scaletype? [英] Android ImageView topCrop/bottomCrop scaletype?

查看:307
本文介绍了Android ImageView topCrop / bottomCrop scaletype?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个方格 ImageView ,它显示不同尺寸的图片。我想始终保持图片的原始宽高比,并且图像周围没有边距(因此图像占据了整个ImageView)。为此,我在 ImageView 上使用 centerCrop scaleType。但是,我想这样做,如果图像的顶部和底部被切断(即:图像高于宽度),图像会被拉向容器的底部。因此,不是在顶部和底部裁剪相等数量的像素,而是图像与 ImageView 的顶部和侧面齐平,图像的底部是两倍裁掉了。这可能在xml中,如果没有,是否有java解决方案?

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?

推荐答案

你将无法用一个常规的 ImageView 以及它在xml中的属性。您可以使用正确的 scaleType Matrix 来实现这一目标,但是写这篇文章是一件痛苦的事。我建议你使用一个可以轻松处理这个问题的受人尊敬的库。例如, CropImageView

You won't be able to do that with a regular ImageView and it's properties in xml. You can accomplish that with a proper scaleType 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 example CropImageView.

这篇关于Android ImageView topCrop / bottomCrop scaletype?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆