Android – how do I rotate the text of a circle created by drawtextonpath horizontally?
•
Android
I have a function that uses drawtextonpath to draw text on the canvas. I calculated the offset. Everything is normal, but I want to draw it in a special way. The current text rotation offset is equal to the circle offset. I want to rotate the text 90 / 45 degrees. But I don't know what to do
Please any ideas
private void drawLegend(Canvas canvas) { canvas.save(Canvas.MATRIX_SAVE_FLAG); canvas.rotate(-228, centerX, centerY); Path circle = new Path(); double halfCircumference = (radius * 2 * Math.PI) - ((radius * 2 * Math.PI) / 8) * 2; double increments = 5; for (int i = 0; i <= this.mMaxSpeed; i += increments) { circle.addCircle(centerX, centerY, radius, Path.Direction.CW); canvas.drawTextOnPath(String.format("%d", i), circle, (float) (i * halfCircumference / this.mMaxSpeed), -20f, scalePaint); } canvas.restore(); }
@H_403_9@
解决方法:
解决方案不是使用drawTextOnPath进行绘制,而是使用drawText在画布上进行绘制
canvas.drawText(String.valueOf(0), (x - width / 2) + 35, (y + height / 2) - 25, scalePaint); canvas.drawText(String.valueOf(5), (x - width / 2) - 20, (y) + 8, scalePaint); canvas.drawText(String.valueOf(10), (x - width / 2) + 30, (y - height / 2) + 40, scalePaint); canvas.drawText(String.valueOf(15), (x), (y - height / 2) - 18, scalePaint); canvas.drawText(String.valueOf(20), (x + width / 2) - 30, (y - height / 2) + 40, scalePaint); canvas.drawText(String.valueOf(25), (x + width / 2) + 25, (y) + 8, scalePaint); canvas.drawText(String.valueOf(30), (x + width / 2) - 35, (y + height / 2) - 25, scalePaint);
@H_403_9@7个月后更新
秘诀是使用sin和cos函数来计算x和y的偏移量.
double theta = (7 * PI / 4) - (i * (2 * PI / 40)); double xPos = radiusScale * 1.2 * Math.sin(theta) + centerX - widthText / 2; double yPos = radiusScale * 1.2 * Math.cos(theta) + centerY + heightText / 2; canvas.drawText(textNotch, (float)xPos, (float)yPos, scalePaint);
@H_403_9@总结
以上是编程之家为你收集整理的android-如何水平旋转由drawTextonPath创建的圆的文本?全部内容,希望文章能够帮你解决android-如何水平旋转由drawTextonPath创建的圆的文本?所遇到的程序开发问题。
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码