widget/DotLottieAnimation Class API Reference
This reference details the properties, methods, and events available in the DotLottieAnimation class, providing a comprehensive guide for developers to effectively utilize this class in their Android applications.
Properties
| Property | Description | Type | Access | 
|---|---|---|---|
| speed | Gets the playback speed of the animation. | Float | Read | 
| loop | Checks if the animation is set to loop. | Boolean | Read | 
| autoplay | Determines if the animation will start playing automatically. | Boolean | Read | 
| isPlaying | Indicates whether the animation is currently playing. | Boolean | Read | 
| isPaused | Indicates whether the animation is paused. | Boolean | Read | 
| isStopped | Indicates whether the animation is stopped. | Boolean | Read | 
| isLoaded | Checks if the animation has been loaded successfully. | Boolean | Read | 
| totalFrames | Gets the total number of frames in the animation. | Float | Read | 
| currentFrame | Gets the current frame of the animation. | Float | Read | 
| playMode | Gets the current play mode of the animation. | Mode | Read | 
| segment | Gets the start and end frames of the current segment being played. | Pair<Float, Float> | Read | 
| duration | Gets the duration of the animation in seconds. | Float | Read | 
| loopCount | Gets the number of times the animation will loop. | UInt | Read | 
| useFrameInterpolation | Checks if frame interpolation is enabled for smoother animation. | Boolean | Read | 
| marker | Gets the current marker of the animation. | String | Read | 
| markers | Gets the list of markers in the animation. | List<Marker> | Read | 
| activeThemeId | Retrieves the ID of the currently active theme. | String | Read | 
| activeAnimationId | Retrieves the ID of the currently active animation. | String | Read | 
XML
The DotLottieAnimation class utilizes a set of XML attributes for configuration within layout XML files. These attributes allow for the customization of animation properties directly from XML. Below is a table summarizing the available XML attributes and their functionalities:
| XML Attribute | Description | Format | Default Value | 
|---|---|---|---|
| dotLottie_src | Specifies the source of the Lottie animation. This can be a local asset filename or a URL to a .lottie or .json file. | string | None | 
| dotLottie_loop | Determines whether the animation should loop indefinitely. | boolean | false | 
| dotLottie_playMode | Defines the play mode of the animation when it reaches the end and the repeat count is greater than 0 or infinite. | enum | normal (1) | 
| dotLottie_speed | Adjusts the playback speed of the animation. A value of 1.0 plays the animation at its normal speed, values greater than 1.0 speed up the playback, and values less than 1.0 slow it down. | float | 1.0f | 
| dotLottie_autoplay | Determines if the animation will start playing automatically upon loading. | boolean | false | 
| dotLottie_backgroundColor | Sets the background color of the animation view. | integer | None | 
| dotLottie_useFrameInterpolation | Enables or disables frame interpolation for smoother animation playback. | boolean | true | 
| dotLottie_themeId | Sets the themeId to load. | string | "" | 
These XML attributes provide a convenient way to configure DotLottieAnimation properties directly within layout files, offering flexibility in setting up animations without the need for additional code.
Methods
| Method | Description | 
|---|---|
| setFrame(frame: Float) | Sets the animation to the specified frame. | 
| setUseFrameInterpolation(enable: Boolean) | Enables or disables frame interpolation for smoother animation playback. | 
| setSegment(firstFrame: Float, lastFrame: Float) | Defines a specific segment of the animation to play, specified by start and end frames. | 
| setLoop(loop: Boolean) | Sets whether the animation should loop. | 
| freeze() | Freezes the animation at the current frame, effectively pausing it. | 
| unFreeze() | Unfreezes the animation, allowing it to continue playing from the frozen frame. | 
| setSpeed(speed: Float) | Adjusts the playback speed of the animation. | 
| play() | Starts or resumes the animation playback. | 
| stop() | Stops the animation and resets it to the beginning. | 
| setPlayMode(repeatMode: Mode) | Sets the play mode of the animation (e.g., forward, reverse). | 
| pause() | Pauses the animation playback. | 
| destroy() | Releases resources associated with the animation. | 
| load(config: Config) | Loads the animation with the specified configuration. | 
| resize(width: Int, height: Int) | Resizes the animation view to the specified width and height. | 
| addEventListener(listener: DotLottieEventListener) | Adds an event listener to receive animation events. | 
| removeEventListener(listener: DotLottieEventListener) | Removes an event listener. | 
| loadStateMachine(stateMachineId: String): Boolean | Loads a specific state machine. | 
| startStateMachine(): Boolean | Starts the state machine. | 
| stopStateMachine(): Boolean | Stops the state machine. | 
| postEvent(event: Event): Boolean | Triggers state machine events. | 
| addStateMachineEventListener(listener: StateMachineEventListener) | Adds a listener for state machine transition events. | 
| removeStateMachineEventListener(listener: StateMachineEventListener) | Removes a state machine transition event listener. | 
| setTheme(themeId: String) | Loads a theme by its ID. | 
| setThemeData(themeData: String) | Loads a theme from the provided theme data | 
| resetTheme() | Resets the theme to the default theme. | 
Events
The DotLottieAnimation class uses the DotLottieEventListener interface to notify about various animation events. Implementations of this interface can listen for the following events:
- onPlay()
- onPause()
- onStop()
- onFrame(frame: Float)
- etc…
This API reference provides a detailed overview of the DotLottieAnimation class, enabling developers to fully leverage its capabilities for integrating and controlling Lottie animations in Android applications.