ImageView scaleType

本文深入解析Android ImageView.ScaleType的各个属性,包括CENTER、CENTER_CROP、CENTER_INSIDE、FIT_CENTER、FIT_END、FIT_START、FIT_XY和MATRIX,通过实例展示其在不同图片尺寸与View尺寸关系下的具体表现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

官方文档如下解释:

ImageView.ScaleType CENTER Center the image in the view, but perform no scaling. 
ImageView.ScaleType 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). 
ImageView.ScaleType 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). 
ImageView.ScaleType 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.
ImageView.ScaleType 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. 
ImageView.ScaleType 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.
ImageView.ScaleType FIT_XY Scale in X and Y independently, so that src matches dst exactly. This may change the aspect ratio of the src.
ImageView.ScaleType MATRIX Scale using the image matrix when drawing. 


下图是图片效果,横向是scaleType的各种属性(与上表从上到下,意义对应。),纵向分别对应的是大图(图片比View大),中图(图片的宽度比View大,高度比View小),小图 (图片比View小)


结合图片效果,来看各个属性的意义:

ImageView.ScaleType CENTER 不进行缩放,居中显示图片。如果图片超出ImageView,则截掉超出的部分。
ImageView.ScaleType CENTER_CROP 等比缩放图片,直到图片的宽度和高度都达到或超过ImageView的宽度和高度。(padding值是负数)
ImageView.ScaleType CENTER_INSIDE 如果图片的宽度或高度超过ImageView的宽度或高度,则缩放图片,直到图片的宽度和高度都小于或等于ImageView的宽度和高度。如果图片的宽高都小于ImageView的宽高,则居中显示图片
ImageView.ScaleType FIT_CENTER 等比缩放图片,直到图片的宽度和高度都小于或等于ImageView的宽度和高度。但是至少要宽度或高度与ImageView的宽度活高度对齐。图片居中显示    
ImageView.ScaleType FIT_END 缩放效果和FIT_CENTER一样,只是图片显示的位置不同。图片显示在右下部
ImageView.ScaleType FIT_START 缩放效果和FIT_CENTER一样,只是图片显示的位置不同。图片显示在左上部
ImageView.ScaleType FIT_XY 不保持图片的原始比例,缩放图片直到宽高和ImageView的宽高一样。
ImageView.ScaleType MATRIX Scale using the image matrix when drawing. (以后研究)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值