imageView ScalType详解

imageView ScalType详解

最近一直在和图片打交道,每次使用scaleType 都是靠不停的试,看哪个图片展示最合适就使用哪个。被代码控制的感受不是很好啊,就花了点时间研究了下scaleType各种类型具体的含义。
废话不多说,先看看google官方的解释:

Google 官方解释

typeenum解释
CENTERCenter the image in the view, but perform no scaling.图片居中放置,不做缩放,图片尺寸大于imageview,则从图片中间裁出同等尺寸图片放置,反之则直接居中放置。
CENTER_CROPScale 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中宽高尺寸大的一边其余裁掉。图片120120, imageView 2030 缩小4倍后,裁掉 。放大:先等比放大图片,达到imageView中宽高中尺寸大的一边,后居中裁剪。例如:图片:2020,imageView 80180,会先放大9倍,后裁剪
CENTER_INSIDEScale 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尺寸:缩小到imageView宽高中尺寸小的一边,其余裁掉。小于的话,则直接放置在中间
FIT_CENTERScale the image using Matrix.ScaleToFit.CENTER.Compute a sc FIT_CENTER ale 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尺寸:缩小到imageView宽高中尺寸小的一边,其余裁掉。 小于的话,放大到imageView宽高中尺寸较小的一边,imageView其余展示背景色。
FIT_ENDScale the image using Matrix.ScaleToFit.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.缩放类似与FIT_CENTER,图片靠END处展示
FIT_STARTScale the image using Matrix.ScaleToFit.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.缩放类似与FIT_CENTER,图片靠START处展示
FIT_XYScale the image using Matrix.ScaleToFit.FILL. Scale in X and Y independently, so that src matches dst exactly. This may change the aspect ratio of the src.宽高独立缩放,用于撑满整个imageView,图片宽高比可能发生变化
MATRIXScale using the image matrix when drawing.通过matrix控制图片缩放,在提供的已有方式中无法满足需求时,可使用

示例图

                            
                            
                            

后面在多说一下matrix这个类型,基本在开发中没有用到过此类型,不过最强大的也是这个matrix,我也只是简单的尝试了下,可以通过matrix,来控制图片的展示方式:

        //设置matrix
        Matrix matrix = new Matrix();
        float scale = (float) 0.2;
        matrix.setScale(scale, scale);
        mIvMatrix.setImageMatrix(matrix);   

##总结
总的来说,在客户端展示上,用CENTER_CROP最优雅,图片不会被拉伸,也可以撑满整个imageView!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值