Answer by sample code:
Also checkout this answer: https://stackoverflow.com/a/22568222/1052261
public class CircleView extends View {
public CircleView(final Context context, final AttributeSet attrs) {
super(context, attrs);
_paint = new Paint();
_paint.setColor(context.getResources().getColor(R.color.colorPrimary));
_paint.setAntiAlias(true);
_paintCenter = new Paint();
_paintCenter.setColor(Color.BLUE);
_paintCenter.setAntiAlias(true);
_timeRingSize = Utils.convertDpToPixel(context, 10);
}
@Override
protected void onDraw(final Canvas canvas) {
final float height = canvas.getHeight();
final float width = canvas.getWidth();
float radious = width > height ? height * 0.5F : width * 0.5F;
final float centerX = canvas.getWidth() * 0.5F;
final float centerY = canvas.getHeight() * 0.5F;
canvas.drawCircle(centerX, centerY, radious, _paint);
RectF rectF = new RectF();
rectF.set(centerX - radious, centerY - radious, centerX + radious, centerY + radious);
canvas.drawArc(rectF, 0, 90, true, _paintCenter);
}
private final float _timeRingSize;
private Paint _paintCenter;
private Paint _paint;
}
Output:
