public class LottieDrawable
extends android.graphics.drawable.Drawable
implements android.graphics.drawable.Drawable.Callback, android.graphics.drawable.Animatable
| Modifier and Type | Class and Description |
|---|---|
static interface |
LottieDrawable.RepeatMode |
| Modifier and Type | Field and Description |
|---|---|
static int |
INFINITE
This value used used with the
setRepeatCount(int) property to repeat
the animation indefinitely. |
static int |
RESTART
When the animation reaches the end and
repeatCount is INFINITE
or a positive value, the animation restarts from the beginning. |
static int |
REVERSE
When the animation reaches the end and
repeatCount is INFINITE
or a positive value, the animation reverses direction on every iteration. |
| Constructor and Description |
|---|
LottieDrawable() |
| 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 |
clearComposition() |
void |
draw(android.graphics.Canvas canvas) |
boolean |
enableMergePathsForKitKatAndAbove() |
void |
enableMergePathsForKitKatAndAbove(boolean enable)
Enable this to get merge path support for devices running KitKat (19) and above.
|
void |
endAnimation() |
int |
getAlpha() |
LottieComposition |
getComposition() |
int |
getFrame()
Get the currently rendered frame.
|
android.graphics.Bitmap |
getImageAsset(java.lang.String id) |
java.lang.String |
getImageAssetsFolder() |
int |
getIntrinsicHeight() |
int |
getIntrinsicWidth() |
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) |
int |
getOpacity() |
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.
|
TextDelegate |
getTextDelegate() |
android.graphics.Typeface |
getTypeface(java.lang.String fontFamily,
java.lang.String style) |
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 who)
These Drawable.Callback methods proxy the calls so that this is the drawable that is
actually invalidated, not a child one which will not pass the view's validateDrawable check.
|
void |
invalidateSelf() |
boolean |
isAnimating() |
boolean |
isLooping() |
boolean |
isMergePathsEnabledForKitKatAndAbove() |
boolean |
isRunning() |
void |
loop(boolean loop)
Deprecated.
|
void |
pauseAnimation() |
void |
playAnimation()
Plays the animation from the beginning.
|
void |
removeAllAnimatorListeners() |
void |
removeAllUpdateListeners() |
void |
removeAnimatorListener(android.animation.Animator.AnimatorListener listener) |
void |
removeAnimatorUpdateListener(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 |
scheduleDrawable(android.graphics.drawable.Drawable who,
java.lang.Runnable what,
long when) |
void |
setAlpha(int alpha) |
void |
setColorFilter(android.graphics.ColorFilter colorFilter) |
boolean |
setComposition(LottieComposition composition)
Create a composition with
LottieCompositionFactory |
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 |
setImagesAssetsFolder(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 |
setMaxFrame(int maxFrame)
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 maxProgress)
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 minFrame)
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 minProgress)
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) |
void |
start() |
void |
stop() |
void |
unscheduleDrawable(android.graphics.drawable.Drawable who,
java.lang.Runnable what) |
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
setImagesAssetsFolder(String) or with an ImageAssetDelegate. |
boolean |
useTextGlyphs() |
applyTheme, canApplyTheme, clearColorFilter, copyBounds, copyBounds, createFromPath, createFromResourceStream, createFromResourceStream, createFromStream, createFromXml, createFromXml, createFromXmlInner, createFromXmlInner, getBounds, getCallback, getChangingConfigurations, getColorFilter, getConstantState, getCurrent, getDirtyBounds, getHotspotBounds, getLayoutDirection, getLevel, getMinimumHeight, getMinimumWidth, getOutline, getPadding, getState, getTransparentRegion, inflate, inflate, isAutoMirrored, isFilterBitmap, isStateful, isVisible, jumpToCurrentState, mutate, onBoundsChange, onLayoutDirectionChanged, onLevelChange, onStateChange, resolveOpacity, scheduleSelf, setAutoMirrored, setBounds, setBounds, setCallback, setChangingConfigurations, setColorFilter, setDither, setFilterBitmap, setHotspot, setHotspotBounds, setLayoutDirection, setLevel, setState, setTint, setTintList, setTintMode, setVisible, unscheduleSelfpublic static final int RESTART
repeatCount is INFINITE
or a positive value, the animation restarts from the beginning.public static final int REVERSE
repeatCount is INFINITE
or a positive value, the animation reverses direction on every iteration.public static final int INFINITE
setRepeatCount(int) property to repeat
the animation indefinitely.public boolean hasMasks()
public boolean hasMatte()
public boolean enableMergePathsForKitKatAndAbove()
public void enableMergePathsForKitKatAndAbove(boolean enable)
Merge paths currently don't work if the the operand shape is entirely contained within the first shape. If you need to cut out one shape from another shape, use an even-odd fill type instead of using merge paths.
public boolean isMergePathsEnabledForKitKatAndAbove()
public void setImagesAssetsFolder(java.lang.String imageAssetsFolder)
If your images are located in src/main/assets/airbnb_loader/ then call `setImageAssetsFolder("airbnb_loader/");`.
If you use LottieDrawable directly, you MUST call #recycleBitmaps() when you
are done. Calling #recycleBitmaps() doesn't have to be final and LottieDrawable
will recreate the bitmaps if needed but they will leak if you don't recycle them.
Be wary if you are using many images, however. Lottie is designed to work with vector shapes from After Effects. If your images look like they could be represented with vector shapes, see if it is possible to convert them to shape layers and re-export your animation. Check the documentation at http://airbnb.io/lottie for more information about importing shapes from Sketch or Illustrator to avoid this.
public java.lang.String getImageAssetsFolder()
public boolean setComposition(LottieComposition composition)
LottieCompositionFactorypublic void setPerformanceTrackingEnabled(boolean enabled)
public PerformanceTracker getPerformanceTracker()
public void clearComposition()
public void invalidateSelf()
invalidateSelf in class android.graphics.drawable.Drawablepublic void setAlpha(int alpha)
setAlpha in class android.graphics.drawable.Drawablepublic int getAlpha()
getAlpha in class android.graphics.drawable.Drawablepublic void setColorFilter(android.graphics.ColorFilter colorFilter)
setColorFilter in class android.graphics.drawable.Drawablepublic int getOpacity()
getOpacity in class android.graphics.drawable.Drawablepublic void draw(android.graphics.Canvas canvas)
draw in class android.graphics.drawable.Drawablepublic void start()
start in interface android.graphics.drawable.Animatablepublic void stop()
stop in interface android.graphics.drawable.Animatablepublic boolean isRunning()
isRunning in interface android.graphics.drawable.Animatablepublic void playAnimation()
public void endAnimation()
public void resumeAnimation()
public void setMinFrame(int minFrame)
public float getMinFrame()
setMinFrame(int) or setMinProgress(float)public void setMinProgress(float minProgress)
public void setMaxFrame(int maxFrame)
public float getMaxFrame()
setMaxFrame(int) or setMaxProgress(float)public void setMaxProgress(float maxProgress)
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 removeAnimatorUpdateListener(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()
public void setFrame(int frame)
public int getFrame()
public void setProgress(float progress)
@Deprecated public void loop(boolean loop)
setRepeatCount(int)public void setRepeatMode(int mode)
public int getRepeatMode()
public void setRepeatCount(int count)
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()
INFINITEpublic boolean isLooping()
public boolean isAnimating()
public void setScale(float scale)
The smaller the animation is, the better the performance will be. You may find that scaling an animation down then rendering it in a larger ImageView and letting ImageView scale it back up with a scaleType such as centerInside will yield better performance with little perceivable quality loss.
You can also use a fixed view width/height in conjunction with the normal ImageView scaleTypes centerCrop and centerInside.
public void setImageAssetDelegate(ImageAssetDelegate assetDelegate)
Be wary if you are using many images, however. Lottie is designed to work with vector shapes from After Effects. If your images look like they could be represented with vector shapes, see if it is possible to convert them to shape layers and re-export your animation. Check the documentation at http://airbnb.io/lottie for more information about importing shapes from Sketch or Illustrator to avoid this.
public void setFontAssetDelegate(FontAssetDelegate assetDelegate)
public void setTextDelegate(TextDelegate textDelegate)
public TextDelegate getTextDelegate()
public boolean useTextGlyphs()
public float getScale()
public LottieComposition getComposition()
public void cancelAnimation()
public void pauseAnimation()
public float getProgress()
public int getIntrinsicWidth()
getIntrinsicWidth in class android.graphics.drawable.Drawablepublic int getIntrinsicHeight()
getIntrinsicHeight in class android.graphics.drawable.Drawablepublic 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:
drawable.addValueCallback(yourKeyPath, LottieProperty.COLOR) { yourColor }public android.graphics.Bitmap updateBitmap(java.lang.String id,
android.graphics.Bitmap bitmap)
setImagesAssetsFolder(String) or with an ImageAssetDelegate.public android.graphics.Bitmap getImageAsset(java.lang.String id)
public android.graphics.Typeface getTypeface(java.lang.String fontFamily,
java.lang.String style)
public void invalidateDrawable(android.graphics.drawable.Drawable who)
invalidateDrawable in interface android.graphics.drawable.Drawable.Callbackpublic void scheduleDrawable(android.graphics.drawable.Drawable who,
java.lang.Runnable what,
long when)
scheduleDrawable in interface android.graphics.drawable.Drawable.Callbackpublic void unscheduleDrawable(android.graphics.drawable.Drawable who,
java.lang.Runnable what)
unscheduleDrawable in interface android.graphics.drawable.Drawable.Callback