Android draw one arc within another arc

user2511882 :

I am trying to draw an arc within another arc at at distance of 10px in Wear OS.

We know that an arc can be drawn using the following:

canvas.drawArc(arcBounds, 0, 90, false, paint);

The above statement will draw an arc from 3pm to 6pm. I would like to draw another arc at the same startAngle and sweepAngle within the above arc.

Assuming that the total number of arc that need to be drawn is based on the size of a list, how can I achieve the expected output?

Here is what my original arcBounds init method looks like:

 private void initArcBounds(int width, int height, int additionalMargin) {
        float margin = res.getDimension(R.dimen.timearc_margin) + additionalMargin;

        arcBounds.left = margin;
        arcBounds.top = margin;
        arcBounds.right = width - margin;
        arcBounds.bottom = height - margin;
    }


for (Event el : eventList) {
      canvas.drawArc(arcBounds, start, sweepAngle, false, timeArcPaints);
      arcBounds.inset(10,10);

}
Mike M. :

To create concentric arcs inward, we just need to "shrink" the bounds by the desired measure on each side. The RectF class has the convenient inset(dx, dy) method which will do just that. It expects those measures in pixels, so we can simply pass 10 for each, with no adjustments needed.

This will modify the RectF's bounds, so to keep those at their initial values in the original, we can create a temporary copy before the draw loop with RectF's copy constructor.

For example, altogether:

RectF temp = new RectF(arcBounds);
for (...) {
    canvas.drawArc(temp, 0, 90, false, paint);
    temp.inset(10f, 10f);
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=154119&siteId=1
arc