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();
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.
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!
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.
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.
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
Try
<com.airbnb.lottie.LottieAnimationView
...
app:lottie_repeatCount="3"
/>
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