Android中ImageView的ScaleType設置

近日發現網上好多關於ScaleType的說明都是錯誤的,因此根據官方文檔和實際的試驗說明一下。

主要分爲matrix、center、fit三類

CENTER

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

按圖片的原來尺寸居中顯示,當圖片長/寬超過View的長/寬,則截取圖片的居中部分顯示

CENTER_CROP

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

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

若原圖尺寸小於view的尺寸,則不進行放縮,直接居中顯示,否則按原圖比例縮小圖片至圖片長寬都必須小於等於view的長寬。結果居中顯示。

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

按原圖比例放縮圖片,保證原圖長寬中至少有一個值與view的長寬相等。結果居中顯示。

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

按原圖比例放縮圖片,保證原圖長寬中至少有一個值與view的長寬相等。結果底部顯示。

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

按原圖比例放縮圖片,保證原圖長寬中至少有一個值與view的長寬相等。結果頂部顯示。

FIT_XY

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

不按比例縮放圖片,目標是把圖片塞滿整個View。

如果不設置scaleType的話,則默認爲FIT_CENTER

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章