简体   繁体   English

在android中的圆形路径上绘制文本

[英]Draw a text on a circle path in android

I need to draw a text on a circle path.我需要在圆形路径上绘制文本。 I have tried the drawTextOnPath() method.我试过drawTextOnPath()方法。 But for texts like "fertile window" in the image attched, the text rotates and is not readable.但是对于附加图像中的“肥沃的窗口”之类的文本,文本会旋转并且不可读。

这是我需要的方式

文本“肥沃的窗口”不可读

Code I have used :我使用过的代码:

customPath2.addArc(mCircleRectF, 30F, 64.28F);
    customPaint2.setAntiAlias(true);
    customPaint2.setDither(true);
    customPaint2.setStrokeWidth(mCircleStrokeWidth);
    customPaint2.setColor(Color.parseColor("#93BE66"));
    customPaint2.setStyle(Paint.Style.STROKE);
    customPaint2.setStrokeCap(Paint.Cap.ROUND);
    canvas.drawPath(customPath2, customPaint2);

    titlePaint.setColor(Color.parseColor("#ffffff"));
    titlePaint.setAntiAlias(true);
    titlePaint.setTypeface(Typeface.MONOSPACE);  titlePaint.setLetterSpacing(0.07F);
    titlePaint.setTextAlign(Paint.Align.CENTER);
    titlePaint.setTextSize(35f);

    canvas.drawTextOnPath("FERTILE WINDOW", customPath2, 0, 8, titlePaint);

Thanks to the comments, to draw the text "outward", make the arc counterclockwise .感谢评论,要“向外”绘制文本,请逆时针绘制弧线。
In your example, startAngle becomes 94.28 and sweepAngle becomes -64.28 .在你的榜样,由startAngle变为94.28sweepAngle变为-64.28

Kotlin:科特林:

val enclosingRect = RectF(0f, 0f, 200f, 200f)
val path = Path()
path.addArc(enclosingRect, 94.28f, -64.28f)
canvas.drawTextOnPath("FERTILE WINDOW", path, 0f, 0f, myPaint)

Java:爪哇:

RectF enclosingRect = new RectF(0f, 0f, 200f, 200f);
Path path = new Path();
path.addArc(enclosingRect, 94.28f, -64.28f);
canvas.drawTextOnPath("FERTILE WINDOW", path, 0f, 0f, myPaint);

That was for texts at the bottom of the circle (from 0 to 180 or from -180 to -360 degrees).那是用于圆圈底部的文本(从0180或从-180-360度)。

For angles between 180 and 360 or 0 and -180 degrees you want to draw the arcs clockwise .对于180度到3600度到-180度之间的角度,您希望顺时针绘制圆弧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM