1

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

Zheng Xian
  • 310
  • 1
  • 3
  • 13

1 Answers1

1

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().

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
  • Do you have any example on how to draw it? – Zheng Xian Jul 14 '16 at 07:31
  • @ZhengXian - Drawing it isn't the problem--just build a `Path` and call `canvas.drawPath(path, paint);`. The problem is how to compute a path. Given your sample image, that's a difficult layout problem that's far different from the question you originally asked. Take a look at [this thread](http://stackoverflow.com/questions/5028433/graph-auto-layout-algorithm) and also search the web for _graph layout algorithms_. – Ted Hopp Jul 14 '16 at 14:16
  • But is there any open source graph layout algorithms for Java API rather than javascript – Zheng Xian Jul 15 '16 at 08:57
  • @ZhengXian - In the thread I referenced, one of the answers suggests using JGraph (a [GitHub project](https://github.com/jgraph/jgraphx)) for Java. I have no experience with this or whether there are other packages available. – Ted Hopp Jul 15 '16 at 11:54