Kanzariya Hitesh
Kanzariya Hitesh

Reputation: 118

Lottie Animation not working correctly in app layout

Lottie Animation not working correctly.

xml file

 <com.airbnb.lottie.LottieAnimationView
                android:id="@+id/check_in_anim"
                android:layout_width="wrap_content"
                app:lottie_autoPlay="true"
                app:lottie_fileName="tenor.json"
                app:lottie_loop="true"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true" />

activity

  LottieAnimationView lottieAnimationView = findViewById(R.id.check_in_anim);
        lottieAnimationView.playAnimation();

enter image description here

my Lottie file: https://lottiefiles.com/6863-tenor

Upvotes: 1

Views: 7308

Answers (2)

Rasel Khan
Rasel Khan

Reputation: 4249

add a Lottie.json file in your res/raw folder enter image description here

Now use this on your tag -->

app:lottie_rawRes="@raw/your_animation"

Full xml code ---->

<com.airbnb.lottie.LottieAnimationView
                android:id="@+id/check_in_anim"
                app:lottie_rawRes="@raw/your_animation"
                android:layout_width="wrap_content"
                app:lottie_autoPlay="true"
                app:lottie_fileName="tenor.json"
                app:lottie_loop="true"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true" />

Upvotes: 1

GOVIND DIXIT
GOVIND DIXIT

Reputation: 1828

Put your lottie json in res/raw and add this to your xml

app:lottie_rawRes="@raw/your_animation"

Like this

<com.airbnb.lottie.LottieAnimationView
                android:id="@+id/check_in_anim"
                app:lottie_rawRes="@raw/your_animation"
                android:layout_width="wrap_content"
                app:lottie_autoPlay="true"
                app:lottie_fileName="tenor.json"
                app:lottie_loop="true"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true" />

For more details. you can look official documentation here

Upvotes: 3

Related Questions