Hesam Khorshidi Hesam Khorshidi - 4 months ago 59
Android Question

Using a Specific Animation in ViewPager

today i was looking for a good way to create animation on ViewPager and i found a good library in github named SparkleMotion . i saw a animation in their demo that a paper playn fly and leave a trace behind . Here's how its look
in fact i only need the trace animation behind the plane and not other animation , can anyone tell me what is this animation and how to use it ?
the github link of the project is :


The source code in that SparkleMotion project you will be most interested in is the PathAnimation class in the main project and the PaperPlaneView class in the demo project.

The animation is centered on the android.graphics.Path class. With the Path class, you can string together straight lines, arcs, rectangles, bezier curves, etc. to form a continuous line.

To render a path, the Canvas class has a drawPath() method. It also has a related method setPathEffect() where you could for example set a DashPathEffect to get the dashed lines.

What makes the animation work is a class called PathMeasure. A PathMeasure object takes a Path in its constructor. This allows you to do measuring operations on the Path. By calling PathMeasure.getSegment() you can get a portion of the path, so by getting longer and longer segments, you can animate the path in motion. And the demo uses the PathMeasure.getPosTan() method to get the position and tangent of the end of the segment. These values are used to position and rotate the paper airplane graphic to look like it is traveling on the path.