I just ran into this issue tonight. For anyone else facing this, the problem is that Android doesn't draw from point 1 to point 2, then point 2 to point 3, point 3 to point 4, etc. It will draw point 1 to 2, then point 3 to 4, etc. So you can also push the previous point twice into whatever data structure you use (I used Vector). So:
private Vector mPoints = new Vector();
private float mLastX = Float.NaN;
private float mLastY = Float.NaN;
public void addPoint(float x, float y) {
if (mLastX == Float.NaN || mLastY == Float.NaN) {
mLastX = x;
mLastY = y;
} else {
mPoints.add(mLastX);
mPoints.add(mLastY);
mPoints.add(x);
mPoints.add(y);
mLastX = x;
mLastY = y;
}
}
Then just make sure to convert your mPoints to a float[] and pass that to canvas.drawLines()
.