Lottie animation not working

19.6k views Asked by At

How can I use Lottie Animation in Android? I tried but the animation doesn't run. How to start the JSON animation? I want to use a custom loading animation instead of using regular circular progress bar.

1

There are 1 answers

0
Kartik Shandilya On BEST ANSWER

Use the Lottie Animation using the following steps:

Add the Gradle dependency to your app

dependencies {  
compile 'com.airbnb.android:lottie:2.2.0'
}

Add the view to Your Layout XML:

<com.airbnb.lottie.LottieAnimationView
    android:id="@+id/animation_view"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:lottie_fileName="preloader.json"//this is the JSON animation stored in assets folder
    app:lottie_loop="true"
    app:lottie_autoPlay="true" />

In your Activity or Fragment init the view:

private LottieAnimationView animationView;
animationView = (LottieAnimationView) findViewById(R.id.animation_view);

Play/Cancel the Animation using:

animationView.playAnimation();
animationView.cancelAnimation();