zoukankan      html  css  js  c++  java
  • android开发使用clipPath快速实现ImageView圆角

    class RoundImageView @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
    ) : AppCompatImageView(context, attrs, defStyleAttr) {

    private val mRadius = 10f
    private val mRoundedRectPath = Path()
    private var width = 0f
    private var height = 0f
    private var isClip = false

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec)
    width = measuredWidth * 1.0f
    height = measuredHeight * 1.0f
    }

    override fun onDraw(canvas: Canvas) {
    if (!isClip) {
    isClip = true
    mRoundedRectPath.reset()
    mRoundedRectPath.moveTo(mRadius, 0f)
    mRoundedRectPath.lineTo(width - mRadius, 0f)
    mRoundedRectPath.quadTo(width, 0f, width, mRadius)
    mRoundedRectPath.lineTo(width, height)
    mRoundedRectPath.lineTo(0f, height)
    mRoundedRectPath.lineTo(0f, mRadius)
    mRoundedRectPath.quadTo(0f, 0f, mRadius, 0f)
    }
    try {
    canvas.clipPath(mRoundedRectPath)
    super.onDraw(canvas)
    } catch (e: Throwable) {
    e.printStackTrace()
    }
    }
    }
     

     

  • 相关阅读:
    docker
    ibus
    看懂gradle
    tcp
    这丫头也的还真清楚,但是跑不通呢,换3.0.3的mybatis也不行
    lsb_release -a
    js中的整型都是用double存储的,有时候不精确,如,
    浏览器缓存及优化
    web即时通信技术
    css 变量
  • 原文地址:https://www.cnblogs.com/yongfengnice/p/13673423.html
Copyright © 2011-2022 走看看