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(JSONObject).
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) |
void |
addColorFilter(android.graphics.ColorFilter colorFilter)
Add a color filter to all layers
|
void |
addColorFilterToContent(java.lang.String layerName,
java.lang.String contentName,
android.graphics.ColorFilter colorFilter)
Add a color filter to specific content on a specific layer.
|
void |
addColorFilterToLayer(java.lang.String layerName,
android.graphics.ColorFilter colorFilter)
Add a color filter to a whole layer
|
void |
cancelAnimation() |
void |
clearColorFilters()
Clear all color filters on all layers and all content in the layers
|
void |
enableMergePathsForKitKatAndAbove(boolean enable)
Enable this to get merge path support for devices running KitKat (19) and above.
|
long |
getDuration() |
int |
getFrame()
Get the currently rendered frame.
|
java.lang.String |
getImageAssetsFolder() |
PerformanceTracker |
getPerformanceTracker() |
float |
getProgress() |
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) |
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 |
removeAnimatorListener(android.animation.Animator.AnimatorListener listener) |
void |
removeUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener updateListener) |
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)
Sets the animation from a JSONObject.
|
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 |
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 |
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 addColorFilterToContent(java.lang.String layerName,
java.lang.String contentName,
android.graphics.ColorFilter colorFilter)
layerName - name of the layer where the supplied content name livescontentName - name of the specific content that the color filter is to be appliedcolorFilter - the color filter, null to clear the color filterpublic void addColorFilterToLayer(java.lang.String layerName,
android.graphics.ColorFilter colorFilter)
layerName - name of the layer that the color filter is to be appliedcolorFilter - the color filter, null to clear the color filterpublic void addColorFilter(android.graphics.ColorFilter colorFilter)
colorFilter - the color filter, null to clear all color filterspublic void clearColorFilters()
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.
public void setAnimation(org.json.JSONObject json)
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 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 addAnimatorListener(android.animation.Animator.AnimatorListener listener)
public void removeAnimatorListener(android.animation.Animator.AnimatorListener listener)
public void loop(boolean loop)
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 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()