0

I want to draw a dashed line from point A to point B

Here is my code:

but the path is never drawn

paintDotted = new Paint();
paintDotted.setAntiAlias(true);
paintDotted.setStyle(Paint.Style.FILL);
paintDotted.setStrokeJoin(Paint.Join.ROUND);
paintCircle.setPathEffect(new CornerPathEffect(20));
paintDotted.setStrokeCap(Paint.Cap.ROUND);
paintDotted.setStrokeWidth(4);

Path dottedPath = new Path();
dottedPath.moveTo(avgStartX, avgEndY);
dottedPath.lineTo(avgEndX,avgEndY);
Log.i("avgStartX",avgStartX+"");
Log.i("avgStartY",avgStartY+"");
Log.i("avgEndY",avgEndY+"");
Log.i("avgEndX",avgEndX+"");
canvas.drawPath(dottedPath, paintDotted);

Please help!

Thanks in advance.

AabidMulani
  • 2,325
  • 1
  • 28
  • 47
  • Are the start and end values sane (give samples)? Where does canvas come from? Is it a screen canvas or a bitmap canvas? Is this the onDraw function or elsewhere? – Gabe Sechan Jun 18 '14 at 17:01
  • No the start and end values are different, and this code is called from the onDraw method of a linear layout – AabidMulani Jun 18 '14 at 17:06

1 Answers1

0

The problem should come from the fact that you are using a Style.FILL on a 1 dimensional element (a line with no height). You have to use Style.STROKE instead.

BTW, if you just want to display a line you should use this:

drawLine(float startX, float startY, float stopX, float stopY, Paint paint)

from the Canvas class. Note that the startY and stopY must be different. This draw will be 2 dimensional and you will be able to use Style.FILL.

G.T.
  • 1,557
  • 1
  • 12
  • 24