A simple Android app that displays an animation with Lottie.
In your module level gradle file:
dependencies {
...
implementation "com.airbnb.android:lottie:$lottieVersion"
...
}
You can find public animations at lottiefiles.com
Load an animation in your src/main/assets
folder.
In your layout file, add a LottieAnimationView
that references your animation file via app:lottie_filename
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/filling_beer_animation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:lottie_fileName="filling_beer.json" />
Then, in your Activity/Fragment simply playAnimation()
.
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
filling_beer_animation.playAnimation()
}
}