How to Add lottie animation in Android Studio Kotlin

In this guide tutorial, you’ll learn step-by-step how to Add lottie animation in Android Studio Kotlin. Animations make apps more interactive and engaging. Instead of creating complex animations manually, you can use Lottie, a library by Airbnb, that renders JSON-based animations exported from After Effects.

What is Lottie Animation in Android Studio Kotlin?

Lottie is an open-source library that parses Adobe After Effects animations exported as JSON and renders them natively on mobile and web.

Why use Lottie Animation In Kotlin?

  • Lightweight compared to GIFs
  • High quality, vector-based
  • Supports scaling without pixelation
  • Easy to use with Android Studio

Example Use Cases for Lottie Animation

  • Splash screen animation
  • Button click effects
  • Success/failure indicators
  • Loading screens

Step-by-Step Guide for Add lottie animation in Android Studio Kotlin

Step 1: Add Dependency in Kotlin Project

In your app/build.gradle file, add the Lottie library:

dependencies {
    implementation "com.airbnb.android:lottie:6.0.0"
}

Sync your project after adding it.


Step 2: Add Lottie Animation File

Download a Lottie JSON file . You can get free animations from: https://app.lottiefiles.com

And put the file in your Android project under: app/src/main/res/raw/animation.json


Step 3: Add Lottie Animation View in Layout

Open your XML layout file (e.g., activity_main.xml) and add:

<com.airbnb.lottie.LottieAnimationView
    android:id="@+id/lottieAnimation"
    android:layout_width="300dp"
    android:layout_height="300dp"
    app:lottie_rawRes="@raw/animation"
    app:lottie_autoPlay="true"
    app:lottie_loop="true"/>
  • lottie_rawRes → points to your animation file in res/raw/.
  • lottie_autoPlay="true" → starts animation automatically.
  • lottie_loop="true" → keeps looping.

Step 4: Control Lottie Animation in Kotlin Code

Inside your MainActivity.kt:

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.airbnb.lottie.LottieAnimationView

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val lottieAnimation = findViewById<LottieAnimationView>(R.id.lottieAnimation)

        // Start animation
        lottieAnimation.playAnimation()

        // Stop animation
        // lottieAnimation.cancelAnimation()

        // Play only once
        // lottieAnimation.repeatCount = 0
    }
}

Step 5: Customize Animation (Optional)

  • Change speed: lottieAnimation.speed = 2.0f // double speed lottieAnimation.speed = 0.5f // half speed
  • Play from specific frame: lottieAnimation.setMinAndMaxFrame(10, 50) lottieAnimation.playAnimation()

Final Output

Lottie animation in Android Studio kotlin Output

See Complete Tutorial on YouTube

Differences Between Lottie and GIF

FeaturesLottieGIF
File SizeSmallLarge
QualityVectorPixel-based
PerformanceSmoothHeavy
Control (Pause/Play)✅ Yes❌ No

Final Thoughts

Using Lottie in Android apps is an easy way to make your app look modern and professional without writing complex animation code. Start with simple animations like a loader or splash screen, and gradually explore interactive ones.

👉 Next, check out:

Leave a Comment

Your email address will not be published. Required fields are marked *