android imageview scaletype,Android ImageView ScaleType: A Visual Guide

If you’re anything like me, you are really, really, ridiculously good looking.

But you’re also probably a tad forgetful. So when it comes time to scale an

image in an ImageView, you cannot for the life of you remember what all the

different ScaleTypes actually look like on the screen. So, you spend the next

10-15 minutes building and rebuilding your app with each and every scale type to

see what they all look like. Then you inevitably forget the difference between

two of them and start the whole process all over again. As the kids say, “I

gotchu fam”.

Below are screenshots of all the different ScaleTypes placed side-by-side. And

below that are all the ScaleType definitions copy and pasted directly from the

official Android docs. And even further below those is a helpful tip for those

brave souls who make it to the end of this post :)

8ab1d778c0d6e3a839eecc7758fbe29a.png

The full descriptions of each ScaleType from the official Android

documentation.

Center the image in the view, but perform no scaling.

Scale the image uniformly (maintain the image’s aspect ratio) so that both

dimensions (width and height) of the image will be equal to or larger than the

corresponding dimension of the view (minus padding).

Scale the image uniformly (maintain the image’s aspect ratio) so that both

dimensions (width and height) of the image will be equal to or less than the

corresponding dimension of the view (minus padding).

Scale the image using Matrix.ScaleToFit.CENTER

Matrix.ScaleToFit.CENTER: Compute a scale that will maintain the original src

aspect ratio, but will also ensure that src fits entirely inside dst. At least

one axis (X or Y) will fit exactly. The result is centered inside dst.

Scale the image using Matrix.ScaleToFit.END

Matrix.ScaleToFit.END: Compute a scale that will maintain the original src

aspect ratio, but will also ensure that src fits entirely inside dst. At least

one axis (X or Y) will fit exactly. END aligns the result to the right and

bottom edges of dst.

Scale the image using Matrix.ScaleToFit.START

Matrix.ScaleToFit.START: Compute a scale that will maintain the original src

aspect ratio, but will also ensure that src fits entirely inside dst. At least

one axis (X or Y) will fit exactly. START aligns the result to the left and top

edges of dst.

Scale the image using Matrix.ScaleToFit.FILL

Matrix.ScaleToFit.FILL: Scale in X and Y independently, so that src matches

dst exactly. This may change the aspect ratio of the src.

Scale using the image matrix when drawing.

While not technically an ImageView.ScaleType this will come in handy. If you

notice with CENTER_INSIDE, FIT_CENTER, FIT_END and FIT_START the actual

bounds of the ImageView are much larger than the scaled image. To set the

bounds of the ImageView to the height of the image inside, use

android:adjustViewBounds="true” in your XML. It looks like this:

0c3d290d9f3404fe7de52676a9731bbd.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值