Answering my own question, I figured out how to do it.
The trick is to use an ObjectAnimator to gradually change the current stroke length and DashPathEffect to control the length of the current stroke. The DashPathEffect parameter will set its own hyphen parameter:
float[] dashes = { 0.0f, Float.MAX_VALUE };
The first float is the length of the visible impact, the second length of the invisible part. The second length is chosen extremely high. The initial settings correspond to a completely invisible shock.
Then, each time the object animator updates the stroke length value, a new DashPathEffect is created with a new visible part and set to the Painter object, and the view is invalid:
dashes[0] = newValue; mPaint.setPathEffect(new DashPathEffect(dashes, 0)); invalidate();
Finally, the onDraw () method uses this artist to draw a path that will contain only the part we want:
canvas.drawPath(path, mPaint);
The only drawback that I see is that we have to create a new DashPathEffect at each step of the animation (since they cannot be reused), but on a global scale this is satisfactory - the animation is nice and smooth.
source share