Last active
April 20, 2022 02:16
-
-
Save gtomek/010599d057ebf2e885d3 to your computer and use it in GitHub Desktop.
How to draw a rounded arc on canvas Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void onDraw(Canvas canvas) { | |
super.onDraw(canvas); | |
mPaint.setStyle(Paint.Style.STROKE); | |
mPaint.setStrokeWidth(50); | |
// Setting the color of the circle | |
mPaint.setColor(Color.BLUE); | |
// Draw the circle at (x,y) with radius 250 | |
int radius = 250; | |
canvas.drawCircle(mX, mY, radius, mPaint); | |
mPaint.setColor(Color.YELLOW); | |
mPaint.setDither(true); // set the dither to true | |
mPaint.setStyle(Paint.Style.STROKE); // set to STOKE | |
mPaint.setStrokeJoin(Paint.Join.ROUND); // set the join to round you want | |
mPaint.setStrokeCap(Paint.Cap.ROUND); // set the paint cap to round too | |
mPaint.setPathEffect(new CornerPathEffect(50) ); // set the path effect when they join. | |
mPaint.setAntiAlias(true); | |
RectF oval = new RectF(mX - radius, mY - radius, mX + radius, mY + radius); | |
canvas.drawArc(oval, -90, 90, false, mPaint); | |
mPaint.setColor(Color.RED); | |
canvas.drawArc(oval, -90, 89, false, mPaint); | |
// Redraw the canvas | |
//invalidate(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment