ImageView的测量与绘制机制解析

  1. mAdjustViewBounds属性

    • True when ImageView is adjusting its bounds to preserve the aspect ratio of its drawable
    • 如果允许adjustViewBounds,ScaleType会强行设置为FIT_CENTER
  2. MaxWidth/MaxHeight机制: 要生效的话,必须setAdjustViewBounds设置为true:

    • E.g, 要设置一个imageView最大为100*100, 3 steps:
      1. set adjustViewBounds to true
      2. set maxWidth and maxHeight to 100
      3. set the height and width layout params to WRAP_CONTENT
  3. setImageResource(int resId):

    • This does Bitmap reading and decoding on the UI thread, which can cause a latency hiccup(Bitmap的读取和解码都是在UI线程完成的,可能会有小卡顿)
  4. ScaleType:

    1. MATRIX, 使用通过setImageMatrix(Matrix)设置的Matrix来**绘制(严格意义上讲,Image本身没有被Matrix改变,改变的是Canvas)**Image
    2. FIT_XY: 对应Matrix.ScaleToFit#FILL:
      • Scale in X and Y independently, so that src matches dst exactly. This may change the aspect ratio of the src.(非等比例放大/缩小Image来完全填充整个View,因此Image的纵横比可能会被改变)
    3. FIT_START: 对应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(等比例放大/缩小Image,同时确保Image不会超出View, 并且至少在一个维度上Image和View的尺寸是相等的, START在这里的意思是经过处理的Image会在左上和View对齐).
    4. FIT_CENTER: 对应Matrix.ScaleToFit#CENTER:
      • 基本同FIT_START,唯一区别是Image在View中是居中的
    5. FIT_END: 对应Matrix.ScaleToFit#END:
      • 基本同FIT_END,唯一区别是Image在右下与View对齐
    6. CENTER: Center the image in the view, but perform no scaling
    7. CENTER_CROP: Scale the image uniformly (maintain the image’s aspect ratio) so that both dimensions (width and height) of
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值