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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值