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

前端 未结 15 2437
后悔当初
后悔当初 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:30

    you can easily achieve this by using Path:

    val radiusArr = floatArrayOf(
        15f, 15f,
        15f, 15f,
        0f, 0f,
        0f, 0f
    )
    val myPath = Path()
    myPath.addRoundRect(
        RectF(0f, 0f, 400f, 400f),
        radiusArr,
        Path.Direction.CW
    )
    
    canvas.drawPath(myPath, paint)
    

提交回复
热议问题