public class LottieAnimationView
extends AppCompatImageView
You may set the animation in one of two ways:
1) Attrs: R.styleable#LottieAnimationView_lottie_fileName
2) Programmatically:
setAnimation(String)
setAnimation(JsonReader, String)
setAnimationFromJson(String, String)
setAnimationFromUrl(String)
setComposition(LottieComposition)
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
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) |
boolean |
addLottieOnCompositionLoadedListener(LottieOnCompositionLoadedListener lottieOnCompositionLoadedListener) |
<T> void |
addValueCallback(KeyPath keyPath,
T property,
LottieValueCallback<T> callback)
Add a 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 |
buildDrawingCache(boolean autoScale)
If rendering via software, Android will fail to generate a bitmap if the view is too large.
|
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() |
float |
getMaxFrame()
Returns the maximum frame set by
setMaxFrame(int) or setMaxProgress(float) |
float |
getMinFrame()
Returns the minimum frame set by
setMinFrame(int) or setMinProgress(float) |
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() |
boolean |
isMergePathsEnabledForKitKatAndAbove()
Returns whether merge paths are enabled for KitKat and above.
|
void |
loop(boolean loop)
Deprecated.
|
protected void |
onAttachedToWindow() |
protected void |
onDetachedFromWindow() |
protected void |
onRestoreInstanceState(android.os.Parcelable state) |
protected android.os.Parcelable |
onSaveInstanceState() |
protected void |
onVisibilityChanged(android.view.View changedView,
int visibility) |
void |
pauseAnimation() |
void |
playAnimation()
Plays the animation from the beginning.
|
void |
removeAllAnimatorListeners() |
void |
removeAllLottieOnCompositionLoadedListener() |
void |
removeAllUpdateListeners() |
void |
removeAnimatorListener(android.animation.Animator.AnimatorListener listener) |
boolean |
removeLottieOnCompositionLoadedListener(LottieOnCompositionLoadedListener lottieOnCompositionLoadedListener) |
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 rawRes)
Sets the animation from a file in the raw directory.
|
void |
setAnimation(android.util.JsonReader reader,
java.lang.String cacheKey)
Sets the animation from a JSONReader.
|
void |
setAnimation(java.lang.String assetName) |
void |
setAnimationFromJson(java.lang.String jsonString)
Deprecated.
|
void |
setAnimationFromJson(java.lang.String jsonString,
java.lang.String cacheKey)
Sets the animation from json string.
|
void |
setAnimationFromUrl(java.lang.String url)
Load a lottie animation from a url.
|
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 |
setMaxFrame(java.lang.String markerName)
Sets the maximum frame to the start time + duration of the specified marker.
|
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 |
setMinAndMaxFrame(java.lang.String markerName)
Sets the minimum and maximum frame to the start time and start time + duration
of the specified marker.
|
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 |
setMinFrame(java.lang.String markerName)
Sets the minimum frame to the start time of the specified marker.
|
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 |
setRenderMode(RenderMode renderMode)
Call this to set whether or not to render with hardware or software acceleration.
|
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 . |
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 onVisibilityChanged(android.view.View changedView, int visibility)
protected void onAttachedToWindow()
protected void onDetachedFromWindow()
public void enableMergePathsForKitKatAndAbove(boolean enable)
public boolean isMergePathsEnabledForKitKatAndAbove()
public void setAnimation(int rawRes)
public void setAnimation(java.lang.String assetName)
@Deprecated public void setAnimationFromJson(java.lang.String jsonString)
setAnimationFromJson(String, String)
public void setAnimationFromJson(java.lang.String jsonString, java.lang.String cacheKey)
public void setAnimation(android.util.JsonReader reader, java.lang.String cacheKey)
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 setAnimationFromUrl(java.lang.String url)
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 float getMinFrame()
setMinFrame(int)
or setMinProgress(float)
public void setMinProgress(float startProgress)
public void setMaxFrame(int endFrame)
public float getMaxFrame()
setMaxFrame(int)
or setMaxProgress(float)
public void setMaxProgress(float endProgress)
public void setMinFrame(java.lang.String markerName)
java.lang.IllegalArgumentException
- if the marker is not found.public void setMaxFrame(java.lang.String markerName)
java.lang.IllegalArgumentException
- if the marker is not found.public void setMinAndMaxFrame(java.lang.String markerName)
java.lang.IllegalArgumentException
- if the marker is not found.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.REVERSE
public int getRepeatMode()
LottieDrawable.REVERSE
or LottieDrawable.RESTART
public 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.INFINITE
public 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 recommended 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 callback'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()
public void buildDrawingCache(boolean autoScale)
public void setRenderMode(RenderMode renderMode)
public boolean addLottieOnCompositionLoadedListener(LottieOnCompositionLoadedListener lottieOnCompositionLoadedListener)
public boolean removeLottieOnCompositionLoadedListener(LottieOnCompositionLoadedListener lottieOnCompositionLoadedListener)
public void removeAllLottieOnCompositionLoadedListener()