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()
    }
    }
    }
     

     

  • 相关阅读:
    20200713 T3 图论
    20200713 T1序列问题
    【题解】P1441 砝码称重
    【题解】P2858 [USACO06FEB]Treats for the Cows G/S
    【比赛】AISing Programming Contest 2019
    20200709 T3 城堡
    20200709 T2 括号
    20200709 T1 笔记
    20200628 T3 网络检查
    个人技术总结
  • 原文地址:https://www.cnblogs.com/yongfengnice/p/13673423.html
Copyright © 2011-2022 走看看