Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set loop number of lottiefiles animation in android(Java)?

I am facing a problem using Lottie files as an animation. I can not set loop number while after loading it is looping continuously but I want to set fixed loop number.

Activity XML

 <com.airbnb.lottie.LottieAnimationView
        android:layout_centerInParent="true"
        android:id="@+id/animation_view_1"
        android:layout_width="150dp"
        android:layout_height="150dp"
        app:lottie_autoPlay="true"
        app:lottie_loop="true" />

Activity Java

animationView.setVisibility(View.VISIBLE);
        animationView.setAnimation(fileName);
        animationView.loop(true);
        animationView.playAnimation();
like image 976
Saiful Islam Avatar asked Jul 18 '19 05:07

Saiful Islam


People also ask

How do I change the size of a Lottie animation?

Give height required for widget in parent SizedBox, then adjust lottie height in the child OverflowBox. Also try using the fit param inside Lottie. asset widget. BoxFit.

How do you set up Lottie animation?

Download the animation, rename it to animation. json or animation. zip depending on your use-case, and place into your raw resources folder. Your first Android project with Lottie animations is ready to go!

How do you play Lottie animation only once?

The Lottie animation will play infinite times, so to make sure that it only plays once, we are going to use the useRef and useEffect hooks so that it only plays once for 3 secs (3000 ms) when the app loads for the first time. We are also going to use the Animated module from React Native.

How do I use LottieFiles on Android?

Approach: Step 1: Add this dependency into the App level gradle module of the project and then sync the gradle with the project. This library enables us to use Lottie's animations: Java.


2 Answers

As animationView.loop(true); is deprecated. In addition to Phan Van Linh asnwer, Using .xml file

<com.airbnb.lottie.LottieAnimationView
        ...
        app:lottie_repeatCount="3"
        />

Using java you can use

animationView.setRepeatCount(LottieDrawable.INFINITE);// for Infinite loops

OR

animationView.setRepeatCount(3);// for 3 loops
like image 71
Amin Pinjari Avatar answered Oct 05 '22 22:10

Amin Pinjari


Try

<com.airbnb.lottie.LottieAnimationView
        ...
        app:lottie_repeatCount="3"
        />
like image 36
Linh Avatar answered Oct 05 '22 22:10

Linh