在android中的圆形路径上绘制文本 [英] Draw a text on a circle path in android

查看:48
本文介绍了在android中的圆形路径上绘制文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在圆形路径上绘制文本.我已经尝试了 drawTextOnPath() 方法.但是对于附图中肥沃的窗口"这样的文字,文字会旋转且不可读.

I need to draw a text on a circle path. I have tried the drawTextOnPath() method. But for texts like "fertile window" in the image attched, the text rotates and is not readable.

我使用过的代码:

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.28sweepAngle 变为 -64.28.

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.

科特林:

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);

这是用于圆圈底部的文本(从 0180 或从 -180-360 度).

That was for texts at the bottom of the circle (from 0 to 180 or from -180 to -360 degrees).

对于 1803600-180 度之间的角度,您要绘制弧线 <强>顺时针.

For angles between 180 and 360 or 0 and -180 degrees you want to draw the arcs clockwise.

这篇关于在android中的圆形路径上绘制文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆