Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tutosrive/lottie-kt-test/llms.txt
Use this file to discover all available pages before exploring further.
LottieAnimationView is the primary UI widget provided by the Lottie library. It extends ImageView, so it slots naturally into any layout. In this demo the view is declared in XML with autoplay and loop attributes so it begins playing immediately once the activity is created, then fine-tuned in Kotlin to load a specific animation file and run it at double speed.
XML Layout Declaration
The view is defined insideactivity_main.xml within a vertical LinearLayout:
app/src/main/res/layout/activity_main.xml
| Attribute | Value | Effect |
|---|---|---|
lottie_autoPlay | true | Starts the animation as soon as the view is attached to the window, without needing an explicit playAnimation() call from XML alone |
lottie_loop | true | Repeats the animation indefinitely after it finishes |
lottie_repeatMode | restart | After each loop the animation jumps back to frame 0 and plays forward again (as opposed to reverse, which would ping-pong) |
android:layout_width="match_parent" and android:layout_height="match_parent" let the animation fill the remaining screen space below the Change button, which is declared just above it in the same LinearLayout.
Kotlin Initialization
InonCreate, MainActivity.kt locates the view with findViewById, loads the animation file, sets playback speed, and starts playback:
MainActivity.kt
setAnimation("wh.json") resolves the filename against the assets/ directory at runtime. No path prefix is needed — the string is the exact filename as it appears inside app/src/main/assets/.lottieView.speed = 2.0f doubles the playback rate: an animation that would ordinarily take 3 seconds to complete will finish in 1.5 seconds. Values below 1.0f slow the animation down; negative values play it in reverse.
The call to lottieView.playAnimation() is technically redundant here because lottie_autoPlay="true" is set in XML, but it is included explicitly to make the intent clear and to ensure playback starts reliably regardless of any XML attribute parsing timing.
Now that the animation is running, learn how to swap between multiple JSON files at runtime: Switching Animations