public class LottieAnimationView
extends AppCompatImageView
You may set the animation in one of two ways:
1) Attrs: R.styleable#LottieAnimationView_lottie_fileName
2) Programatically: setAnimation(String), setComposition(LottieComposition),
or setAnimation(JsonReader).
You can set a default cache strategy with R.attr#lottie_cacheStrategy.
You can manually set the progress of the animation with setProgress(float) or
R.attr#lottie_progress
| Modifier and Type | Class and Description |
|---|---|
static class |
LottieAnimationView.CacheStrategy
Caching strategy for compositions that will be reused frequently.
|
| Constructor and Description |
|---|
LottieAnimationView(android.content.Context context) |
LottieAnimationView(android.content.Context context,
android.util.AttributeSet attrs) |
LottieAnimationView(android.content.Context context,
android.util.AttributeSet attrs,
int defStyleAttr) |
| Modifier and Type | Method and Description |
|---|---|
void |
addAnimatorListener(android.animation.Animator.AnimatorListener listener) |
void |
addAnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener updateListener) |
<T> void |
addValueCallback(KeyPath keyPath,
T property,
LottieValueCallback<T> callback)
Add an property callback for the specified
KeyPath. |
<T> void |
addValueCallback(KeyPath keyPath,
T property,
SimpleLottieValueCallback<T> callback)
Overload of
addValueCallback(KeyPath, Object, LottieValueCallback) that takes an interface. |
void |
cancelAnimation() |
void |
enableMergePathsForKitKatAndAbove(boolean enable)
Enable this to get merge path support for devices running KitKat (19) and above.
|
LottieComposition |
getComposition() |
long |
getDuration() |
int |
getFrame()
Get the currently rendered frame.
|
java.lang.String |
getImageAssetsFolder() |
PerformanceTracker |
getPerformanceTracker() |
float |
getProgress() |
int |
getRepeatCount()
Defines how many times the animation should repeat.
|
int |
getRepeatMode()
Defines what this animation should do when it reaches the end.
|
float |
getScale() |
float |
getSpeed()
Returns the current playback speed.
|
boolean |
hasMasks()
Returns whether or not any layers in this composition has masks.
|
boolean |
hasMatte()
Returns whether or not any layers in this composition has a matte layer.
|
void |
invalidateDrawable(android.graphics.drawable.Drawable dr) |
boolean |
isAnimating() |
void |
loop(boolean loop)
Deprecated.
|
protected void |
onAttachedToWindow() |
protected void |
onDetachedFromWindow() |
protected void |
onRestoreInstanceState(android.os.Parcelable state) |
protected android.os.Parcelable |
onSaveInstanceState() |
void |
pauseAnimation() |
void |
playAnimation()
Plays the animation from the beginning.
|
void |
removeAllAnimatorListeners() |
void |
removeAllUpdateListeners() |
void |
removeAnimatorListener(android.animation.Animator.AnimatorListener listener) |
void |
removeUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener updateListener) |
java.util.List<KeyPath> |
resolveKeyPath(KeyPath keyPath)
|
void |
resumeAnimation()
Continues playing the animation from its current position.
|
void |
reverseAnimationSpeed()
Reverses the current animation speed.
|
void |
setAnimation(int animationResId)
Sets the animation from a file in the raw directory.
|
void |
setAnimation(int animationResId,
LottieAnimationView.CacheStrategy cacheStrategy)
Sets the animation from a file in the raw directory.
|
void |
setAnimation(org.json.JSONObject json)
Deprecated.
|
void |
setAnimation(android.util.JsonReader reader)
Sets the animation from a JSONReader.
|
void |
setAnimation(java.lang.String animationName)
Sets the animation from a file in the assets directory.
|
void |
setAnimation(java.lang.String animationName,
LottieAnimationView.CacheStrategy cacheStrategy)
Sets the animation from a file in the assets directory.
|
void |
setAnimationFromJson(java.lang.String jsonString)
Sets the animation from json string.
|
void |
setComposition(LottieComposition composition)
Sets a composition.
|
void |
setFontAssetDelegate(FontAssetDelegate assetDelegate)
Use this to manually set fonts.
|
void |
setFrame(int frame)
Sets the progress to the specified frame.
|
void |
setImageAssetDelegate(ImageAssetDelegate assetDelegate)
Use this if you can't bundle images with your app.
|
void |
setImageAssetsFolder(java.lang.String imageAssetsFolder)
If you use image assets, you must explicitly specify the folder in assets/ in which they are
located because bodymovin uses the name filenames across all compositions (img_#).
|
void |
setImageBitmap(android.graphics.Bitmap bm) |
void |
setImageDrawable(android.graphics.drawable.Drawable drawable) |
void |
setImageResource(int resId) |
void |
setMaxFrame(int endFrame)
Sets the maximum frame that the animation will end at when playing or looping.
|
void |
setMaxProgress(float endProgress)
Sets the maximum progress that the animation will end at when playing or looping.
|
void |
setMinAndMaxFrame(int minFrame,
int maxFrame) |
void |
setMinAndMaxProgress(float minProgress,
float maxProgress) |
void |
setMinFrame(int startFrame)
Sets the minimum frame that the animation will start from when playing or looping.
|
void |
setMinProgress(float startProgress)
Sets the minimum progress that the animation will start from when playing or looping.
|
void |
setPerformanceTrackingEnabled(boolean enabled) |
void |
setProgress(float progress) |
void |
setRepeatCount(int count)
Sets how many times the animation should be repeated.
|
void |
setRepeatMode(int mode)
Defines what this animation should do when it reaches the end.
|
void |
setScale(float scale)
Set the scale on the current composition.
|
void |
setSpeed(float speed)
Sets the playback speed.
|
void |
setTextDelegate(TextDelegate textDelegate)
Set this to replace animation text with custom text at runtime
|
android.graphics.Bitmap |
updateBitmap(java.lang.String id,
android.graphics.Bitmap bitmap)
Allows you to modify or clear a bitmap that was loaded for an image either automatically
through
setImageAssetsFolder(String) or with an ImageAssetDelegate. |
void |
useExperimentalHardwareAcceleration()
Deprecated.
|
void |
useExperimentalHardwareAcceleration(boolean use)
Deprecated.
|
void |
useHardwareAcceleration() |
void |
useHardwareAcceleration(boolean use)
Enable hardware acceleration for this view.
|
public LottieAnimationView(android.content.Context context)
public LottieAnimationView(android.content.Context context,
android.util.AttributeSet attrs)
public LottieAnimationView(android.content.Context context,
android.util.AttributeSet attrs,
int defStyleAttr)
public void setImageResource(int resId)
public void setImageDrawable(android.graphics.drawable.Drawable drawable)
public void setImageBitmap(android.graphics.Bitmap bm)
public void invalidateDrawable(android.graphics.drawable.Drawable dr)
protected android.os.Parcelable onSaveInstanceState()
protected void onRestoreInstanceState(android.os.Parcelable state)
protected void onAttachedToWindow()
protected void onDetachedFromWindow()
public void enableMergePathsForKitKatAndAbove(boolean enable)
@Deprecated public void useExperimentalHardwareAcceleration()
useHardwareAcceleration(boolean)@Deprecated public void useExperimentalHardwareAcceleration(boolean use)
useHardwareAcceleration(boolean)public void useHardwareAcceleration()
useHardwareAcceleration(boolean)public void useHardwareAcceleration(boolean use)
public void setAnimation(int animationResId)
Will not cache the composition once loaded.
public void setAnimation(int animationResId,
LottieAnimationView.CacheStrategy cacheStrategy)
You may also specify a cache strategy. Specifying LottieAnimationView.CacheStrategy.Strong will hold a
strong reference to the composition once it is loaded
and deserialized. LottieAnimationView.CacheStrategy.Weak will hold a weak reference to said composition.
public void setAnimation(java.lang.String animationName)
Will not cache the composition once loaded.
public void setAnimation(java.lang.String animationName,
LottieAnimationView.CacheStrategy cacheStrategy)
You may also specify a cache strategy. Specifying LottieAnimationView.CacheStrategy.Strong will hold a
strong reference to the composition once it is loaded
and deserialized. LottieAnimationView.CacheStrategy.Weak will hold a weak reference to said composition.
@Deprecated public void setAnimation(org.json.JSONObject json)
public void setAnimationFromJson(java.lang.String jsonString)
public void setAnimation(android.util.JsonReader reader)
This is particularly useful for animations loaded from the network. You can fetch the bodymovin json from the network and pass it directly here.
public void setComposition(LottieComposition composition)
R.attr#lottie_cacheStrategy.public LottieComposition getComposition()
public boolean hasMasks()
public boolean hasMatte()
public void playAnimation()
public void resumeAnimation()
public void setMinFrame(int startFrame)
public void setMinProgress(float startProgress)
public void setMaxFrame(int endFrame)
public void setMaxProgress(float endProgress)
public void setMinAndMaxFrame(int minFrame,
int maxFrame)
setMinFrame(int),
setMaxFrame(int)public void setMinAndMaxProgress(float minProgress,
float maxProgress)
setMinProgress(float),
setMaxProgress(float)public void reverseAnimationSpeed()
setSpeed(float),
playAnimation(),
resumeAnimation()public void setSpeed(float speed)
public float getSpeed()
public void addAnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener updateListener)
public void removeUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener updateListener)
public void removeAllUpdateListeners()
public void addAnimatorListener(android.animation.Animator.AnimatorListener listener)
public void removeAnimatorListener(android.animation.Animator.AnimatorListener listener)
public void removeAllAnimatorListeners()
@Deprecated public void loop(boolean loop)
setRepeatCount(int)public void setRepeatMode(int mode)
LottieDrawable.INFINITE. Defaults to LottieDrawable.RESTART.mode - LottieDrawable.RESTART or LottieDrawable.REVERSEpublic int getRepeatMode()
LottieDrawable.REVERSE or LottieDrawable.RESTARTpublic void setRepeatCount(int count)
LottieDrawable.INFINITE, the repeat mode will be taken
into account. The repeat count is 0 by default.count - the number of times the animation should be repeatedpublic int getRepeatCount()
LottieDrawable.INFINITEpublic boolean isAnimating()
public void setImageAssetsFolder(java.lang.String imageAssetsFolder)
public java.lang.String getImageAssetsFolder()
public android.graphics.Bitmap updateBitmap(java.lang.String id,
android.graphics.Bitmap bitmap)
setImageAssetsFolder(String) or with an ImageAssetDelegate.public void setImageAssetDelegate(ImageAssetDelegate assetDelegate)
public void setFontAssetDelegate(FontAssetDelegate assetDelegate)
public void setTextDelegate(TextDelegate textDelegate)
public java.util.List<KeyPath> resolveKeyPath(KeyPath keyPath)
KeyPath, potentially with wildcards or globstars and resolve it to a list of
zero or more actual Keypaths that exist in the current animation.
If you want to set value callbacks for any of these values, it is recommend to use the
returned KeyPath objects because they will be internally resolved to their content
and won't trigger a tree walk of the animation contents when applied.public <T> void addValueCallback(KeyPath keyPath, T property, LottieValueCallback<T> callback)
KeyPath. This KeyPath can resolve
to multiple contents. In that case, the callbacks's value will apply to all of them.
Internally, this will check if the KeyPath has already been resolved with
resolveKeyPath(KeyPath) and will resolve it if it hasn't.public <T> void addValueCallback(KeyPath keyPath, T property, SimpleLottieValueCallback<T> callback)
addValueCallback(KeyPath, Object, LottieValueCallback) that takes an interface. This allows you to use a single abstract
method code block in Kotlin such as:
animationView.addValueCallback(yourKeyPath, LottieProperty.COLOR) { yourColor }public void setScale(float scale)
public float getScale()
public void cancelAnimation()
public void pauseAnimation()
public void setFrame(int frame)
public int getFrame()
public void setProgress(float progress)
public float getProgress()
public long getDuration()
public void setPerformanceTrackingEnabled(boolean enabled)
public PerformanceTracker getPerformanceTracker()