Skip to content

Instantly share code, notes, and snippets.

@fada21
Last active August 29, 2015 13:55
Show Gist options
  • Save fada21/8721867 to your computer and use it in GitHub Desktop.
Save fada21/8721867 to your computer and use it in GitHub Desktop.
PathAnimation class for Android
package com.coolands.open;
import android.graphics.Path;
import android.graphics.PathMeasure;
import android.view.animation.Animation;
import android.view.animation.Transformation;
/**
* Animation along path
* by Ewan Chou (https://github.com/coocood)
*/
public class PathAnimation extends Animation {
private PathMeasure measure;
private float[] pos = new float[2];
public PathAnimation(Path path) {
measure = new PathMeasure(path, false);
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t){
measure.getPosTan(measure.getLength() * interpolatedTime, pos,null);
t.getMatrix().setTranslate(pos[0], pos[1]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment