Sah*_*kar 5 android canvas drawtext ondraw android-canvas
我需要在圆形路径上绘制文本.我试过这个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);
Run Code Online (Sandbox Code Playgroud)
感谢评论的帮助,要“向外”绘制文本,请逆时针制作弧线。
在您的示例中,startAngle变为94.28,sweepAngle变为-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)
Run Code Online (Sandbox Code Playgroud)
爪哇:
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);
Run Code Online (Sandbox Code Playgroud)
这是针对圆圈底部的文本(从0到180或从-180到-360度)。
对于180和360或0和度之间的角度,您需要顺时针-180绘制圆弧。
| 归档时间: |
|
| 查看次数: |
2944 次 |
| 最近记录: |