ImageView缩放选项

ImageView.ScaleType

将图片边界缩放到所在view边界时的缩放选项。
Options for scaling the bounds of an image to the bounds of this view.

不同选项含义

CENTER

居中,不缩放。

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

CENTER_CROP

居中,如果图片宽或高比view小,就等比放大使得宽和高都大于等于view,计算时view大小减去对应padding值。
比如view是100x100,图片是120x50,view的padding为10,那么就放大至(100 - 2*10) / 50 = 1.6倍。
图片宽高都大于等于view时无需任何缩放。

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).

CENTER_INSIDE

居中,如果图片宽或高比view大,就等比缩小使得宽或高都小于等于view,计算时view大小减去对应padding值。
比如view是100x100,图片是120x50,view的padding为10,那么就缩小至(100 - 2*10) / 120 = 2/3倍。
图片宽高都小于等于view时无需任何缩放。

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).

FIT_CENTER

居中,填充,等比缩放使得宽高都小于等于view,其中宽或高至少一个和view相等。
和CENTER_INSIDE的不同是总是保证至少宽或高中一个和view相等。

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 entered inside dst.

FIT_END

右下对齐,填充,等比缩放使得宽高都小于等于view,其中宽或高至少一个和view相等。

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.

FIT_START

左上对齐,填充,等比缩放使得宽高都小于等于view,其中宽或高至少一个和view相等。

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.

FIT_XY

非等比缩放,让图片宽高和view一致。

Scale in X and Y independently, so that src matches dst exactly. This may change the aspect ratio of the src.

MATRIX

使用指定的matrix对象缩放。

Scale using the image matrix when drawing. The image matrix can be set using setImageMatrix(Matrix).

上面是预置的缩放选项,可以看到,还有一些缩放效果没有提供,可以自己通过setImageMatrix实现。比如,和FIT_CENTER相对的,使得宽和高都大于等于view,宽和高至少一个相等。

(本文使用Atom编写)

原文地址:https://www.cnblogs.com/everhad/p/5913386.html