How to use android canvas to draw a Rectangle with only topleft and topright corners round?

前端 未结 15 2427
后悔当初
后悔当初 2020-11-29 01:58

I found a function for rectangles with all 4 corners being round, but I want to have just the top 2 corners round. What can I do?

canvas.drawRoundRect(new Re         


        
15条回答
  •  佛祖请我去吃肉
    2020-11-29 02:23

    Use PaintDrawable could be better:

        val topLeftRadius = 10
        val topRightRadius = 10
        val bottomLeftRadius = 0
        val bottomRightRadius = 0
        val rect = Rect(0, 0, 100, 100)
        val paintDrawable = PaintDrawable(Color.RED)
        val outter = floatArrayOf(topLeftRadius, topLeftRadius, topRightRadius, topRightRadius,
                bottomLeftRadius, bottomLeftRadius, bottomRightRadius, bottomRightRadius)
        paintDrawable.setCornerRadii(outter)
        paintDrawable.bounds = rect
        paintDrawable.draw(canvas)
    

提交回复
热议问题