Lottie-android: how to reverse animation?

Created on 12 Feb 2017  路  7Comments  路  Source: airbnb/lottie-android

I want to playing reverse animation after cancel animation.

Instead of using Handler and LottieAnimView.setProgress(x) to reverse played time,
i want to find other ways.
ex) ValueAnimator.reverse()

Most helpful comment

Could we possibly have a setSpeed(float) method and pass -1 to reverse the animation ?

All 7 comments

I solved this issue. but I think you have to support method in LottieAnimView.

        float progress = animView.getProgress();
        ValueAnimator valueAnimator = ValueAnimator.ofFloat(-progress,0 ).setDuration((long) ( animView.getDuration()* progress));
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {

                animView.setProgress(Math.abs((float)animation.getAnimatedValue()));
            }
        });
        valueAnimator.start();

Could we possibly have a setSpeed(float) method and pass -1 to reverse the animation ?

@martinbonnin you got it :)

Fixed by 0ca8ad8

Will be in 1.0.3

I tried using it in 3.5.0, but I couldn't find the method to reverse the view. It seems that the method might have been removed. Passing -1 to setSpeed(float) works fine, however.

@sijanr That is the correct way to do this.

@gpeal Great! I've just started using Lottie and totally love it so far.

Was this page helpful?
0 / 5 - 0 ratings