Android library for rendering Adobe After Effects animations exported as JSON through Bodymovin with native performance and extensive customization options.
—
Primary UI components for displaying Lottie animations in Android layouts and custom views. These components handle animation lifecycle, rendering, and user interaction.
Main view component that extends AppCompatImageView for easy integration in Android layouts. Provides automatic lifecycle management and declarative configuration through XML attributes.
/**
* View component for displaying Lottie animations in layouts
*/
public class LottieAnimationView extends AppCompatImageView {
// Animation loading methods
public void setAnimation(String fileName);
public void setAnimation(int rawResId);
public void setAnimation(InputStream stream, String cacheKey);
public void setAnimationFromUrl(String url);
public void setAnimationFromUrl(String url, String cacheKey);
public void setAnimationFromJson(String json);
public void setAnimationFromJson(String jsonString, String cacheKey);
public void setComposition(LottieComposition composition);
// Playback control methods
public void playAnimation();
public void pauseAnimation();
public void resumeAnimation();
public void cancelAnimation();
public boolean isAnimating();
// Progress and timing control
public void setProgress(float progress);
public float getProgress();
public void setSpeed(float speed);
public float getSpeed();
public void reverseAnimationSpeed();
public long getDuration();
public int getFrame();
public void setRepeatCount(int count);
public int getRepeatCount();
public void setRepeatMode(@RepeatMode int mode);
public @RepeatMode int getRepeatMode();
public void loop(boolean loop);
// Frame control
public void setFrame(int frame);
public void setMinFrame(int startFrame);
public void setMaxFrame(int endFrame);
public void setMinAndMaxFrame(int startFrame, int endFrame);
public void setMinProgress(float startProgress);
public void setMaxProgress(float endProgress);
public void setMinAndMaxProgress(float startProgress, float endProgress);
// Marker-based control
public void setMinAndMaxFrame(String markerName);
public void setMinAndMaxFrame(String startMarkerName, String endMarkerName);
public void playAnimation(String markerName);
public void playAnimation(String startMarkerName, String endMarkerName);
// Dynamic properties
public <T> void addValueCallback(KeyPath keyPath, T property, LottieValueCallback<T> callback);
public <T> void addValueCallback(KeyPath keyPath, T property, SimpleLottieValueCallback<T> callback);
public List<KeyPath> resolveKeyPath(KeyPath keyPath);
// Delegates and customization
public void setImageAssetDelegate(ImageAssetDelegate delegate);
public void setFontAssetDelegate(FontAssetDelegate delegate);
public void setTextDelegate(TextDelegate delegate);
// Rendering configuration
public void setRenderMode(RenderMode mode);
public RenderMode getRenderMode();
public void enableMergePathsForKitKatAndAbove(boolean enable);
public boolean isMergePathsEnabledForKitKatAndAbove();
public void setApplyingOpacityToLayersEnabled(boolean isApplyingOpacityToLayersEnabled);
public void disableExtraScaleModeInFitXY();
public void setClipToCompositionBounds(boolean clipToCompositionBounds);
public boolean getClipToCompositionBounds();
public void setCacheComposition(boolean cacheComposition);
public void setOutlineMasksAndMattes(boolean outline);
public void setSafeMode(boolean safeMode);
public void setIgnoreDisabledSystemAnimations(boolean ignore);
public void setPerformanceTrackingEnabled(boolean enabled);
public PerformanceTracker getPerformanceTracker();
// Listeners
public void addAnimatorListener(Animator.AnimatorListener listener);
public void removeAnimatorListener(Animator.AnimatorListener listener);
public void removeAllAnimatorListeners();
public void addAnimatorUpdateListener(ValueAnimator.AnimatorUpdateListener listener);
public void removeAnimatorUpdateListener(ValueAnimator.AnimatorUpdateListener listener);
public void removeAllUpdateListeners();
public void addAnimatorPauseListener(Animator.AnimatorPauseListener listener);
public void removeAnimatorPauseListener(Animator.AnimatorPauseListener listener);
public void addLottieOnCompositionLoadedListener(LottieOnCompositionLoadedListener listener);
public void removeLottieOnCompositionLoadedListener(LottieOnCompositionLoadedListener listener);
public void removeAllLottieOnCompositionLoadedListener();
// Composition access
public LottieComposition getComposition();
// Failure handling
public void setFailureListener(LottieListener<Throwable> failureListener);
public void setFallbackResource(int fallbackResource);
}XML Attributes:
<com.airbnb.lottie.LottieAnimationView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:lottie_fileName="animation.json"
app:lottie_rawRes="@raw/animation"
app:lottie_url="https://example.com/animation.json"
app:lottie_autoPlay="true"
app:lottie_loop="true"
app:lottie_repeatMode="restart"
app:lottie_repeatCount="3"
app:lottie_speed="1.5"
app:lottie_progress="0.5"
app:lottie_cacheComposition="true"
app:lottie_renderMode="automatic"
app:lottie_enableMergePathsForKitKatAndAbove="true"
app:lottie_fallbackRes="@drawable/fallback_image" />Usage Examples:
// Basic usage in Activity
LottieAnimationView animationView = findViewById(R.id.animation_view);
animationView.setAnimation("loading_animation.json");
animationView.playAnimation();
// Control playback
animationView.setSpeed(2.0f); // Double speed
animationView.setRepeatCount(LottieDrawable.INFINITE);
animationView.addAnimatorListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animator) {
// Animation completed
}
});
// Play specific segments
animationView.playAnimation("intro", "loop");
animationView.setMinAndMaxFrame("loading_start", "loading_end");
// Dynamic property modification
animationView.addValueCallback(
new KeyPath("**"),
LottieProperty.COLOR,
new LottieValueCallback<>(Color.RED)
);
// Load from URL with error handling
animationView.setAnimationFromUrl("https://example.com/animation.json");
animationView.setFailureListener(throwable -> {
Log.e("Lottie", "Failed to load animation", throwable);
});Drawable implementation for programmatic use in custom views, ImageViews, and complex layouts. Provides full control over rendering and lifecycle without view overhead.
/**
* Drawable implementation for rendering Lottie animations programmatically
*/
public class LottieDrawable extends Drawable implements Animatable {
// Composition management
public void setComposition(LottieComposition composition);
public LottieComposition getComposition();
// Playback control
public void start();
public void stop();
public void pause();
public void resume();
public boolean isRunning();
// Progress and timing control
public void setProgress(float progress);
public float getProgress();
public void setSpeed(float speed);
public float getSpeed();
public void setRepeatCount(int count);
public int getRepeatCount();
public void setRepeatMode(int mode);
public int getRepeatMode();
// Frame control
public void setFrame(int frame);
public void setMinFrame(int startFrame);
public void setMaxFrame(int endFrame);
public void setMinAndMaxFrame(int startFrame, int endFrame);
public void setMinProgress(float startProgress);
public void setMaxProgress(float endProgress);
public void setMinAndMaxProgress(float startProgress, float endProgress);
// Marker-based control
public void setMinAndMaxFrame(String markerName);
public void setMinAndMaxFrame(String startMarkerName, String endMarkerName);
public void playAnimation(String markerName);
public void playAnimation(String startMarkerName, String endMarkerName);
// Dynamic properties
public <T> void addValueCallback(KeyPath keyPath, T property, LottieValueCallback<T> callback);
public <T> void addValueCallback(KeyPath keyPath, T property, SimpleLottieValueCallback<T> callback);
public List<KeyPath> resolveKeyPath(KeyPath keyPath);
// Delegates and customization
public void setImageAssetDelegate(ImageAssetDelegate delegate);
public void setFontAssetDelegate(FontAssetDelegate delegate);
public void setTextDelegate(TextDelegate delegate);
// Rendering configuration
public void setRenderMode(RenderMode mode);
public RenderMode getRenderMode();
public void enableMergePathsForKitKatAndAbove(boolean enable);
public void setApplyingOpacityToLayersEnabled(boolean isApplyingOpacityToLayersEnabled);
public void setClipToCompositionBounds(boolean clipToCompositionBounds);
// System animations
public void setSystemAnimationsAreEnabled(boolean areSystemAnimationsEnabled);
public void setIgnoreDisabledSystemAnimations(boolean ignore);
// Listeners
public void addAnimatorListener(Animator.AnimatorListener listener);
public void removeAnimatorListener(Animator.AnimatorListener listener);
public void addAnimatorUpdateListener(ValueAnimator.AnimatorUpdateListener updateListener);
public void removeAnimatorUpdateListener(ValueAnimator.AnimatorUpdateListener updateListener);
// Performance tracking
public PerformanceTracker getPerformanceTracker();
public void setPerformanceTrackingEnabled(boolean enabled);
// Safe mode for problematic animations
public void setSafeMode(boolean safeMode);
}Usage Examples:
// Basic drawable usage
LottieDrawable drawable = new LottieDrawable();
LottieCompositionFactory.fromAsset(context, "animation.json")
.addListener(drawable::setComposition);
ImageView imageView = findViewById(R.id.image_view);
imageView.setImageDrawable(drawable);
drawable.playAnimation();
// In custom view
public class CustomAnimatedView extends View {
private LottieDrawable lottieDrawable;
public CustomAnimatedView(Context context) {
super(context);
lottieDrawable = new LottieDrawable();
lottieDrawable.setCallback(this);
LottieCompositionFactory.fromAsset(context, "custom_animation.json")
.addListener(composition -> {
lottieDrawable.setComposition(composition);
lottieDrawable.playAnimation();
});
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
lottieDrawable.draw(canvas);
}
@Override
protected boolean verifyDrawable(Drawable drawable) {
return drawable == lottieDrawable || super.verifyDrawable(drawable);
}
}
// Advanced control
drawable.setSpeed(0.5f);
drawable.setRepeatMode(ValueAnimator.REVERSE);
drawable.setRepeatCount(3);
// Frame-based animation
drawable.setMinAndMaxFrame(30, 120);
drawable.setProgress(0.25f); // Jump to 25% of the segment
// Performance monitoring
drawable.setPerformanceTrackingEnabled(true);
PerformanceTracker tracker = drawable.getPerformanceTracker();public interface LottieOnCompositionLoadedListener {
void onCompositionLoaded(LottieComposition composition);
}Install with Tessl CLI
npx tessl i tessl/maven-com-airbnb-android--lottie