Basic Usage
Common use cases for the DotLottieAnimation
composable function include loading and displaying dotLottie animations within Jetpack Compose UIs. The following example demonstrates how to integrate a dotLottie animation into a Composable function using the DotLottieAnimation
composable function.
Loading from different sources
From a URL
DotLottieSource.Url
is used to load an animation from a URL. It can load .json
or .lottie
files from a URL.
From an asset
DotLottieSource.Asset
is used to load an animation from the assets folder in your Android project. It can load .json
or .lottie
files from the assets folder.
From raw data
DotLottieSource.Data is used to load an animation from raw data. It can load .lottie
files from raw data.
From a JSON string
DotLottieSource.Json
is used to load an animation from a JSON string. It can load .json
files from a JSON string.
Changing background color
Using the Modifier
parameter, you can change the background color of the DotLottieAnimation
composable function.
Adjusting animation display size
Note: width
and height
properties are for controlling canvas size, not the animation size. The animation will be scaled to fit the canvas size. If your animation is pixelated, you can try to increase the canvas size. We’re working on a feature to give users more control over the animation size, like fill
, fit
, center
, etc. Stay tuned for updates on this feature.
If you want to control the animation size, you can use the Modifier
parameter to set the size. You can use the width
,height
or size
modifier to set the size of the DotLottieAnimation
composable function. fillMaxWidth()
, fillMaxSize()
, etc. can also be used to control the size of the animation.