我需要在圆形路径上绘制文本。
我试过 drawTextOnPath()
方法。但是对于所附图像中的“肥沃窗口”之类的文本,文本会旋转并且不可读。
我用过的代码:
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);
最佳答案
感谢评论的帮助,将文字“向外”绘制,制作弧线逆时针 .
在您的示例中, startAngle 变为 94.28
并且sweepAngle 变为-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);
这适用于圆圈底部的文本(从 0
到 180
或从 -180
到 -360
度)。对于
180
之间的角度和 360
或 0
和 -180
您要绘制弧线的度数顺时针 .
关于android - 在android中的圆形路径上绘制文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38657335/