简体   繁体   English

如何在Android中使用Canvas Paint在弧顶上绘制线路径

[英]How to draw line path on top of arc using Canvas paint in Android

I am working in an android application where i need to draw a graph like this. 我正在一个Android应用程序中工作,我需要绘制这样的图形。

I have drawn the arc using paint and canvas but i didn't know how to draw the line path along with the text as mentioned in below picture! 我已经使用油漆和画布绘制了弧线,但是我不知道如何绘制直线路径以及下面的图片中提到的文字!

Any heads up on this would be really helpful for me. 任何对此的注意都会对我有很大帮助。 Thanks in advance. 提前致谢。

在此处输入图片说明

In order to keep direction of the line truly, you have to use many trigonometric functions and calculus. 为了真正保持直线方向,您必须使用许多三角函数和微积分。 However, for such cases you can use canvas.rotate() for tricky solution. 但是,在这种情况下,可以使用canvas.rotate()获得棘手的解决方案。 For the solution, first you calculate angle of line according to a value. 对于解决方案,首先要根据一个值计算直线角度。 For example, assume your arc represents total value of 200. The left side is 0 and the right side is 200, then you get the value of 80. With these values, you can calculate the angle like that 180degree * (80f)/(200 - 0) it gives 72 degree. 例如,假设圆弧代表的总值为200。左侧为0,右侧为200,则得到的值为80。使用这些值,您可以计算出180度*(80f)/( 200-0)给出72度。 Then you can rotate the canvas for drawing canvas.rotate(70f,centerX,centerY) . 然后,您可以旋转画布以绘制canvas.rotate(70f,centerX,centerY) CenterX and CenterY are values of the center point of the arc. CenterX和CenterY是圆弧中心点的值。 After that, you can draw your line as you draw to line at the left-bottom corner of the canvas canvas.drawLine(0,100,20,100,paint) . 之后,您可以在画布canvas.drawLine(0,100,20,100,paint)左下角绘制线条时绘制线条。

canvas.save()
canvas.rotate(70f,centerX,centerY)
canvas.drawLine(0,100,20,100,paint)
canvas.restore()

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

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