Native Mobile App Development With Java

Android Lottie animation example java

08-Oct-2024

Android Lottie example


1/ Add dependency on Lottie animation

implementation ("com.airbnb.android:lottie:6.5.2")



2/   Create an Android Resource Directory  - Click on res >  Android Resource Directory >  Directory name  (raw) >  Resource Type  (Raw).  Download the  Lottie JSON file  from  https://lottiefiles.com  and paste the JSON file into  Raw  directory  




3/  XML File - Set AutoPlay =   true  to play the file automatically and set Lottie_loop =   true  to play the video repeatedly. 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<com.airbnb.lottie.LottieAnimationView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:lottie_rawRes="@raw/animation"
app:lottie_autoPlay="true"
app:lottie_loop="true"/>
</RelativeLayout>



Comments