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

前端 未结 15 2362
后悔当初
后悔当初 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条回答
  •  Happy的楠姐
    2020-11-29 02:19

    draw round rect with left rounded corners

      private void drawRoundRect(float left, float top, float right, float bottom, Paint paint, Canvas canvas) {
            Path path = new Path();
            path.moveTo(left, top);
            path.lineTo(right, top);
            path.lineTo(right, bottom);
            path.lineTo(left + radius, bottom);
            path.quadTo(left, bottom, left, bottom - radius);
            path.lineTo(left, top + radius);
            path.quadTo(left, top, left + radius, top);
            canvas.drawPath(path, onlinePaint);
        }
    

提交回复
热议问题