I'm pretty much looking for exactly what the question suggests - a DecelerateAccelerateInterpolator
. What I want to do is have an animation decelerate for the first half of the animation, and then accelerate after that. (I'm using it to mimic a gravity-like effect on a Bèzier curve).
EDIT:
Basically, what I'm looking for is something that as the object moves upward on the screen along a Bèzier curve, it decelerates until it gets to the top (at which point it momentarily stops, or has 0 speed or whatever), and then it starts to accelerate as it travels back down the other side.
If you're using Android API 21 or greater you can use PathInterpolator with a cubic Bezier curve:
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
TimeInterpolator lInter = new PathInterpolator(0.0f, 0.97f, 1.0f, 0.03f);
animation.setInterpolator(lInter);
}
And here's a great website for calculating your desired bezier curve values:
Try to use my custom Interpolator. And you're welcome :)
mAnimation.setInterpolator(new Interpolator() {
@Override
public float getInterpolation(float pInput) {
System.out.println("input " + pInput);
// (1-(1-(x*2))^3)/2
return (float) (1 - Math.pow(1 - (2 * pInput), 3)) / 2;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With