You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Lottie Compose:如何让动画无限循环播放?

实现Lottie动画无限循环播放

要让你的Lottie动画无限循环,最直接的方式是在LottieAnimation组件中添加repeatCount参数,并设置为LottieConstants.IterateForever:

val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.search_animation))
LottieAnimation(
    composition = composition,
    repeatCount = LottieConstants.IterateForever
)

补充说明

  • LottieConstants.IterateForever是Lottie库提供的内置常量,值为-1,用于指定动画无限重复。
  • 如果需要更精细化的动画控制(比如手动启停、调整播放速率等),可以通过rememberLottieAnimatable管理动画状态:
val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.search_animation))
val animatable = rememberLottieAnimatable()

// 当动画资源加载完成后启动无限循环
LaunchedEffect(composition) {
    composition?.let {
        animatable.animate(
            composition = it,
            iterations = LottieConstants.IterateForever
        )
    }
}

LottieAnimation(
    composition = composition,
    progress = animatable.progress
)

内容的提问来源于stack exchange,提问作者Roberto Leinardi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 16:48:58