or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

asset-management.mdcomposition-loading.mdconfiguration-performance.mddynamic-properties.mdindex.mdview-components.md

view-components.mddocs/

0

# View Components

1

2

Primary UI components for displaying Lottie animations in Android layouts and custom views. These components handle animation lifecycle, rendering, and user interaction.

3

4

## Capabilities

5

6

### LottieAnimationView

7

8

Main view component that extends AppCompatImageView for easy integration in Android layouts. Provides automatic lifecycle management and declarative configuration through XML attributes.

9

10

```java { .api }

11

/**

12

* View component for displaying Lottie animations in layouts

13

*/

14

public class LottieAnimationView extends AppCompatImageView {

15

// Animation loading methods

16

public void setAnimation(String fileName);

17

public void setAnimation(int rawResId);

18

public void setAnimation(InputStream stream, String cacheKey);

19

public void setAnimationFromUrl(String url);

20

public void setAnimationFromUrl(String url, String cacheKey);

21

public void setAnimationFromJson(String json);

22

public void setAnimationFromJson(String jsonString, String cacheKey);

23

public void setComposition(LottieComposition composition);

24

25

// Playback control methods

26

public void playAnimation();

27

public void pauseAnimation();

28

public void resumeAnimation();

29

public void cancelAnimation();

30

public boolean isAnimating();

31

32

// Progress and timing control

33

public void setProgress(float progress);

34

public float getProgress();

35

public void setSpeed(float speed);

36

public float getSpeed();

37

public void reverseAnimationSpeed();

38

public long getDuration();

39

public int getFrame();

40

public void setRepeatCount(int count);

41

public int getRepeatCount();

42

public void setRepeatMode(@RepeatMode int mode);

43

public @RepeatMode int getRepeatMode();

44

public void loop(boolean loop);

45

46

// Frame control

47

public void setFrame(int frame);

48

public void setMinFrame(int startFrame);

49

public void setMaxFrame(int endFrame);

50

public void setMinAndMaxFrame(int startFrame, int endFrame);

51

public void setMinProgress(float startProgress);

52

public void setMaxProgress(float endProgress);

53

public void setMinAndMaxProgress(float startProgress, float endProgress);

54

55

// Marker-based control

56

public void setMinAndMaxFrame(String markerName);

57

public void setMinAndMaxFrame(String startMarkerName, String endMarkerName);

58

public void playAnimation(String markerName);

59

public void playAnimation(String startMarkerName, String endMarkerName);

60

61

// Dynamic properties

62

public <T> void addValueCallback(KeyPath keyPath, T property, LottieValueCallback<T> callback);

63

public <T> void addValueCallback(KeyPath keyPath, T property, SimpleLottieValueCallback<T> callback);

64

public List<KeyPath> resolveKeyPath(KeyPath keyPath);

65

66

// Delegates and customization

67

public void setImageAssetDelegate(ImageAssetDelegate delegate);

68

public void setFontAssetDelegate(FontAssetDelegate delegate);

69

public void setTextDelegate(TextDelegate delegate);

70

71

// Rendering configuration

72

public void setRenderMode(RenderMode mode);

73

public RenderMode getRenderMode();

74

public void enableMergePathsForKitKatAndAbove(boolean enable);

75

public boolean isMergePathsEnabledForKitKatAndAbove();

76

public void setApplyingOpacityToLayersEnabled(boolean isApplyingOpacityToLayersEnabled);

77

public void disableExtraScaleModeInFitXY();

78

public void setClipToCompositionBounds(boolean clipToCompositionBounds);

79

public boolean getClipToCompositionBounds();

80

public void setCacheComposition(boolean cacheComposition);

81

public void setOutlineMasksAndMattes(boolean outline);

82

public void setSafeMode(boolean safeMode);

83

public void setIgnoreDisabledSystemAnimations(boolean ignore);

84

public void setPerformanceTrackingEnabled(boolean enabled);

85

public PerformanceTracker getPerformanceTracker();

86

87

// Listeners

88

public void addAnimatorListener(Animator.AnimatorListener listener);

89

public void removeAnimatorListener(Animator.AnimatorListener listener);

90

public void removeAllAnimatorListeners();

91

public void addAnimatorUpdateListener(ValueAnimator.AnimatorUpdateListener listener);

92

public void removeAnimatorUpdateListener(ValueAnimator.AnimatorUpdateListener listener);

93

public void removeAllUpdateListeners();

94

public void addAnimatorPauseListener(Animator.AnimatorPauseListener listener);

95

public void removeAnimatorPauseListener(Animator.AnimatorPauseListener listener);

96

public void addLottieOnCompositionLoadedListener(LottieOnCompositionLoadedListener listener);

97

public void removeLottieOnCompositionLoadedListener(LottieOnCompositionLoadedListener listener);

98

public void removeAllLottieOnCompositionLoadedListener();

99

100

// Composition access

101

public LottieComposition getComposition();

102

103

// Failure handling

104

public void setFailureListener(LottieListener<Throwable> failureListener);

105

public void setFallbackResource(int fallbackResource);

106

}

107

```

108

109

**XML Attributes:**

110

111

```xml

112

<com.airbnb.lottie.LottieAnimationView

113

android:layout_width="wrap_content"

114

android:layout_height="wrap_content"

115

app:lottie_fileName="animation.json"

116

app:lottie_rawRes="@raw/animation"

117

app:lottie_url="https://example.com/animation.json"

118

app:lottie_autoPlay="true"

119

app:lottie_loop="true"

120

app:lottie_repeatMode="restart"

121

app:lottie_repeatCount="3"

122

app:lottie_speed="1.5"

123

app:lottie_progress="0.5"

124

app:lottie_cacheComposition="true"

125

app:lottie_renderMode="automatic"

126

app:lottie_enableMergePathsForKitKatAndAbove="true"

127

app:lottie_fallbackRes="@drawable/fallback_image" />

128

```

129

130

**Usage Examples:**

131

132

```java

133

// Basic usage in Activity

134

LottieAnimationView animationView = findViewById(R.id.animation_view);

135

animationView.setAnimation("loading_animation.json");

136

animationView.playAnimation();

137

138

// Control playback

139

animationView.setSpeed(2.0f); // Double speed

140

animationView.setRepeatCount(LottieDrawable.INFINITE);

141

animationView.addAnimatorListener(new AnimatorListenerAdapter() {

142

@Override

143

public void onAnimationEnd(Animator animator) {

144

// Animation completed

145

}

146

});

147

148

// Play specific segments

149

animationView.playAnimation("intro", "loop");

150

animationView.setMinAndMaxFrame("loading_start", "loading_end");

151

152

// Dynamic property modification

153

animationView.addValueCallback(

154

new KeyPath("**"),

155

LottieProperty.COLOR,

156

new LottieValueCallback<>(Color.RED)

157

);

158

159

// Load from URL with error handling

160

animationView.setAnimationFromUrl("https://example.com/animation.json");

161

animationView.setFailureListener(throwable -> {

162

Log.e("Lottie", "Failed to load animation", throwable);

163

});

164

```

165

166

### LottieDrawable

167

168

Drawable implementation for programmatic use in custom views, ImageViews, and complex layouts. Provides full control over rendering and lifecycle without view overhead.

169

170

```java { .api }

171

/**

172

* Drawable implementation for rendering Lottie animations programmatically

173

*/

174

public class LottieDrawable extends Drawable implements Animatable {

175

// Composition management

176

public void setComposition(LottieComposition composition);

177

public LottieComposition getComposition();

178

179

// Playback control

180

public void start();

181

public void stop();

182

public void pause();

183

public void resume();

184

public boolean isRunning();

185

186

// Progress and timing control

187

public void setProgress(float progress);

188

public float getProgress();

189

public void setSpeed(float speed);

190

public float getSpeed();

191

public void setRepeatCount(int count);

192

public int getRepeatCount();

193

public void setRepeatMode(int mode);

194

public int getRepeatMode();

195

196

// Frame control

197

public void setFrame(int frame);

198

public void setMinFrame(int startFrame);

199

public void setMaxFrame(int endFrame);

200

public void setMinAndMaxFrame(int startFrame, int endFrame);

201

public void setMinProgress(float startProgress);

202

public void setMaxProgress(float endProgress);

203

public void setMinAndMaxProgress(float startProgress, float endProgress);

204

205

// Marker-based control

206

public void setMinAndMaxFrame(String markerName);

207

public void setMinAndMaxFrame(String startMarkerName, String endMarkerName);

208

public void playAnimation(String markerName);

209

public void playAnimation(String startMarkerName, String endMarkerName);

210

211

// Dynamic properties

212

public <T> void addValueCallback(KeyPath keyPath, T property, LottieValueCallback<T> callback);

213

public <T> void addValueCallback(KeyPath keyPath, T property, SimpleLottieValueCallback<T> callback);

214

public List<KeyPath> resolveKeyPath(KeyPath keyPath);

215

216

// Delegates and customization

217

public void setImageAssetDelegate(ImageAssetDelegate delegate);

218

public void setFontAssetDelegate(FontAssetDelegate delegate);

219

public void setTextDelegate(TextDelegate delegate);

220

221

// Rendering configuration

222

public void setRenderMode(RenderMode mode);

223

public RenderMode getRenderMode();

224

public void enableMergePathsForKitKatAndAbove(boolean enable);

225

public void setApplyingOpacityToLayersEnabled(boolean isApplyingOpacityToLayersEnabled);

226

public void setClipToCompositionBounds(boolean clipToCompositionBounds);

227

228

// System animations

229

public void setSystemAnimationsAreEnabled(boolean areSystemAnimationsEnabled);

230

public void setIgnoreDisabledSystemAnimations(boolean ignore);

231

232

// Listeners

233

public void addAnimatorListener(Animator.AnimatorListener listener);

234

public void removeAnimatorListener(Animator.AnimatorListener listener);

235

public void addAnimatorUpdateListener(ValueAnimator.AnimatorUpdateListener updateListener);

236

public void removeAnimatorUpdateListener(ValueAnimator.AnimatorUpdateListener updateListener);

237

238

// Performance tracking

239

public PerformanceTracker getPerformanceTracker();

240

public void setPerformanceTrackingEnabled(boolean enabled);

241

242

// Safe mode for problematic animations

243

public void setSafeMode(boolean safeMode);

244

}

245

```

246

247

**Usage Examples:**

248

249

```java

250

// Basic drawable usage

251

LottieDrawable drawable = new LottieDrawable();

252

LottieCompositionFactory.fromAsset(context, "animation.json")

253

.addListener(drawable::setComposition);

254

255

ImageView imageView = findViewById(R.id.image_view);

256

imageView.setImageDrawable(drawable);

257

drawable.playAnimation();

258

259

// In custom view

260

public class CustomAnimatedView extends View {

261

private LottieDrawable lottieDrawable;

262

263

public CustomAnimatedView(Context context) {

264

super(context);

265

lottieDrawable = new LottieDrawable();

266

lottieDrawable.setCallback(this);

267

268

LottieCompositionFactory.fromAsset(context, "custom_animation.json")

269

.addListener(composition -> {

270

lottieDrawable.setComposition(composition);

271

lottieDrawable.playAnimation();

272

});

273

}

274

275

@Override

276

protected void onDraw(Canvas canvas) {

277

super.onDraw(canvas);

278

lottieDrawable.draw(canvas);

279

}

280

281

@Override

282

protected boolean verifyDrawable(Drawable drawable) {

283

return drawable == lottieDrawable || super.verifyDrawable(drawable);

284

}

285

}

286

287

// Advanced control

288

drawable.setSpeed(0.5f);

289

drawable.setRepeatMode(ValueAnimator.REVERSE);

290

drawable.setRepeatCount(3);

291

292

// Frame-based animation

293

drawable.setMinAndMaxFrame(30, 120);

294

drawable.setProgress(0.25f); // Jump to 25% of the segment

295

296

// Performance monitoring

297

drawable.setPerformanceTrackingEnabled(true);

298

PerformanceTracker tracker = drawable.getPerformanceTracker();

299

```

300

301

## Listener Interfaces

302

303

```java { .api }

304

public interface LottieOnCompositionLoadedListener {

305

void onCompositionLoaded(LottieComposition composition);

306

}

307

```