I know that it may be a little late, but I came up with this approach from the iOS project, first draw the outline and then draw the fill
arc
protected void onDraw(Canvas canvas) { super.onDraw(canvas); float width = (float)getWidth(); float height = (float)getHeight(); float radius; //Get radius from the bigger size if (width > height){ radius = height/2; }else{ radius = width/2; } //Create Paint Object Paint paint = new Paint(); paint.setColor(Color.RED); paint.setFilterBitmap(true); paint.setAntiAlias(true); paint.setStrokeWidth(5); paint.setStyle(Paint.Style.STROKE); //Create Contour Object Path path = new Path(); float center_x, center_y; center_x = width/2; center_y = height/2; //Configure rect for the outer ring final RectF oval = new RectF(); oval.set(center_x - radius + 5, center_y - radius + 5, center_x + radius - 5, center_y + radius - 5); //Add outer arc path.addArc(oval, 0, 90); //Configure rect for the inner ring oval.set(center_x - radius + 30, center_y - radius + 30, center_x + radius - 30, center_y + radius - 30); //Add inner arc to the path but draw counterclockwise path.arcTo(oval, -270, -90); //close path path.close(); //Create Paint Object Paint fillPaint = new Paint(); fillPaint.setColor(Color.YELLOW); fillPaint.setFilterBitmap(true); fillPaint.setAntiAlias(true); fillPaint.setStrokeWidth(21); fillPaint.setStyle(Paint.Style.STROKE); //Create Contour Object Path fillPath = new Path(); //Configure rect for the fill ring oval.set(center_x - radius + 17, center_y - radius + 17, center_x + radius - 17, center_y + radius - 17); //Add fill arc fillPath.addArc(oval, 0, 90); //draw fill path canvas.drawPath(fillPath,fillPaint); //draw outer path canvas.drawPath(path, paint); }
Useful link: http://www.programering.com/a/MDO1czNwATE.html , where addarc mathematical data is described in sufficient detail
source share