天天看點

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編寫)