본문 바로가기
안드로이드 코틀린

[Android][Kotlin] Animation으로 Lottie를 사용해보기

by teamnova 2022. 7. 28.

1. build.gradle에 Lottie 를 추가합니다.

// 로티
implementation 'com.airbnb.android:lottie:3.7.0'

 

2. asset folder를 생성합니다.

 

 

> 사용할 Lottie Anmation 찾기 : https://lottiefiles.com/search?q=space&category=animations

 

Free Lottie Animation Files, Tools & Plugins - LottieFiles

The world’s largest online platform for the world’s smallest animation format for designers, developers, and more. Access Lottie animation tools and plugins for Android, iOS, and Web.

lottiefiles.com

 

 

3. Lottie를 사용할 폴더 안에 적용해줍니다.

 

app:lottie_fileName="space.json" -> 여기에 asset 폴더에 있는 사용하실 파일명을 입력하시면 됩니다.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.airbnb.lottie.LottieAnimationView
        android:id="@+id/lottie"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:lottie_autoPlay="true"
        app:lottie_fileName="space.json"
        app:lottie_loop="true" />


</androidx.constraintlayout.widget.ConstraintLayout>

 

 

간단하게 애니메이션이 보이는 것을 알 수 있습니다.