Zheng Xian
Zheng Xian

Reputation: 320

How to draw a curved arrow in canvas android

I have this code to draw the arrow tail line between 2 point but how should I draw curved line for arrow tail?

canvas.drawLine(pt1[X], pt1[Y], pt2[X], pt2[Y], paint);//draw line

I want to have something like this, whereby the arrow is dynamic

enter image description here

Upvotes: 1

Views: 1783

Answers (1)

Ted Hopp
Ted Hopp

Reputation: 234795

Depending on what shape you want for the curved line, you could perhaps use Canvas.drawArc(), but that is restricted to sections of an oval aligned with the screen axes.

For a more general approach, define your curved line as a Path and then use Canvas.drawPath() to render it to the canvas. A Path can be composed of an arbitrary number of straight line, quadratic curve, and cubic curve segments. (See the docs for how to construct the Path that you want.) For a solid arrow tail, you should set the paint's style to FILL when calling drawPath().

Upvotes: 1

Related Questions