Lucas Heise
Lucas Heise

Reputation: 149

Lottie - setProgress is not working properly

I have an animation using Lottie that works fine, the problem is, let's say that my animation is a ball that grows and shrinks (like if it's beating), when the user press the ball, I need it to 'grow to be at its maximum size' so I'd need to set my animation progress to 1 (right?).

This works fine, but the problem is that I want the ball to 'grow' until it gets to its maximum size, not just go from 0 to 1 in a fraction of a second, does anyone know how to do this? (sorry if my question is kind of not well formulated...)

Here's the code that I tried to write: (this code makes the ball go from 0 to 1 in a fraction of a second and not like if it's growing)

    LottieAnimationView unclickedAnimation = ...

    unclickedAnimation.pauseAnimation();

    float currentProgress = unclickedAnimation.getProgress();

    for(float i = currentProgress; i < 1.0f; i += 0.01f) {
        unclickedAnimation.setProgress(i);
    }

Thanks already

Upvotes: 1

Views: 5193

Answers (2)

Faisal Ahmed
Faisal Ahmed

Reputation: 125

If I am able to understand your question correctly, I think all you need to do is play your Lottie animation on click of the LottieAnimationView. The following code may help you understand.

Say your animation json goes from smallest ball size to largest, then -

     unclickedAnimation.setOnClickListener(v -> {
              unclickedAnimation.playAnimation();
});

Furthermore if you want to loop or set the max frame/ min frame for your animation, you can use -

 unclickedAnimation.loop(true);
 unclickedAnimation.setMaxProgress(/*value here*/);

Upvotes: 1

Christian Findsen
Christian Findsen

Reputation: 31

With your currect code you just set the animation to show a specific frame. You want to set the maxProgress and then play the animation.

So if you want it to go from half size to full size you would start with a maxProgress(0.5f); and pause it there. When the users clicks you set the new parameters:

 unclickedAnimation.setMaxProgress(1f);
 unclickedAnimation.resumeAnimation();

Upvotes: 2

Related Questions