参考
具体描述可以参考 Android ImageView 的scaleType 属性图解 - 简书 (jianshu.com)
图解
这里只做图解,为了方便对比,分了图片尺寸大于 ImageView 和图片尺寸小于 ImageView 两种情况;同时,分了长大于宽和宽大于长两种情况。














备注
由于是用 PPT 画的图,导出图片的时候超过 PPT 边界的地方就被裁掉了,但是不影响理解,重点看红色虚线框就可以,其代表 ImageView。
单独解释下:
-
FIT_CENTER 和 CENTER_INSIDE 的区别,当图片尺寸大于 ImageView 尺寸时,二者表现一致。当图片尺寸小于 ImageView 尺寸时,FIT_CENTER 会放大,CENTER_INSIDE 则保持原始尺寸。简单记:FIT_CENTER 可缩小可放大,CENTER_INSIDE 只缩小不放大。
-
CENTER 不会改变图片尺寸,以原始尺寸和 ImageView 中心点重合即可,ImageView 能显示多少就显示多少
-
一般情况,直接用 CENTER_CROP 即可,它会缩放至充满整个 ImageView(可能会造成左右或者上下部分不可见)
网友评论