Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inverse of AccelerateDecelerateInterpolator on Android

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.

like image 236
jwir3 Avatar asked Jan 11 '23 13:01

jwir3


2 Answers

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:

like image 62
Jon Bryant Avatar answered Jan 31 '23 09:01

Jon Bryant


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;
    }
});
like image 43
Enes Avatar answered Jan 31 '23 07:01

Enes