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

PropertyDescriptionTypeAccess
speedGets the playback speed of the animation.FloatRead
loopChecks if the animation is set to loop.BooleanRead
autoplayDetermines if the animation will start playing automatically.BooleanRead
isPlayingIndicates whether the animation is currently playing.BooleanRead
isPausedIndicates whether the animation is paused.BooleanRead
isStoppedIndicates whether the animation is stopped.BooleanRead
isLoadedChecks if the animation has been loaded successfully.BooleanRead
totalFramesGets the total number of frames in the animation.FloatRead
currentFrameGets the current frame of the animation.FloatRead
playModeGets the current play mode of the animation.ModeRead
segmentGets the start and end frames of the current segment being played.Pair<Float, Float>Read
durationGets the duration of the animation in seconds.FloatRead
loopCountGets the number of times the animation will loop.UIntRead
useFrameInterpolationChecks if frame interpolation is enabled for smoother animation.BooleanRead
markerGets the current marker of the animation.StringRead
markersGets the list of markers in the animation.List<Marker>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 AttributeDescriptionFormatDefault Value
dotLottie_srcSpecifies the source of the Lottie animation. This can be a local asset filename or a URL to a .lottie or .json file.stringNone
dotLottie_loopDetermines whether the animation should loop indefinitely.booleanfalse
dotLottie_playModeDefines the play mode of the animation when it reaches the end and the repeat count is greater than 0 or infinite.enumnormal (1)
dotLottie_speedAdjusts 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.float1.0f
dotLottie_autoplayDetermines if the animation will start playing automatically upon loading.booleanfalse
dotLottie_backgroundColorSets the background color of the animation view.integerNone
dotLottie_useFrameInterpolationEnables or disables frame interpolation for smoother animation playback.booleantrue

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

MethodDescription
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): BooleanLoads a specific state machine.
startStateMachine(): BooleanStarts the state machine.
stopStateMachine(): BooleanStops the state machine.
postEvent(event: Event): BooleanTriggers state machine events.
addStateMachineEventListener(listener: StateMachineEventListener)Adds a listener for state machine transition events.
removeStateMachineEventListener(listener: StateMachineEventListener)Removes a state machine transition event listener.

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.