Android: looking for a drawArc() method with inner & outer radius

后端 未结 5 1723
逝去的感伤
逝去的感伤 2020-11-29 17:49

I have the following custom view:

\"alt

This I have achieved by using the Canvas\' drawArc

5条回答
  •  星月不相逢
    2020-11-29 18:17

    You can do this:

        Paint paint = new Paint();
        final RectF rect = new RectF();
        //Example values
        rect.set(mWidth/2- mRadius, mHeight/2 - mRadius, mWidth/2 + mRadius, mHeight/2 + mRadius); 
        paint.setColor(Color.GREEN);
        paint.setStrokeWidth(20);
        paint.setAntiAlias(true);
        paint.setStrokeCap(Paint.Cap.ROUND);
        paint.setStyle(Paint.Style.STROKE);
        canvas.drawArc(rect, -90, 360, false, paint);
    

    The key is in paint.setStyle(Paint.Style.STROKE);, it crops the arc's center with the stroke that you define in setStrokeWidth (in the example draws an arc with a radius of mRadius and 20px thick).

    Hope it helps!

提交回复
热议问题