Lottie动画
一、 Lottie介绍
Lottie 是 Airbnb 开源的一套跨平台的完整的动画效果解决方案,设计师可以使用 Adobe After Effects 设计出漂亮的动画之后,使用 Lottic 提供的 Bodymovin 插件将设计好的动画导出成 JSON 格式,就可以直接运用在 iOS、Android、Web 和 React Native之上,无需其他额外操作。
二、 使用
最简单的使用方法是使用 LottieAnimationView。Lottie 支持加载来自 res/raw 或 assets/ 的动画资源。建议使用 res/raw,因为可以对动画通过 R 文件使用静态引用,而不只是使用字符串名称。这也可以帮助构建静态分析,因为它可以跟踪动画的使用。
- 导包 implementation ‘com.airbnb.android:lottie:3.4.4’
- 在 res/raw或 assets/中存放动画的 JSON 文件
- xml中自定义view
<com.example.model.ProgressLottieAniView
android:id="@+id/detail_progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:lottie_fileName="progress_bar.json"
app:lottie_loop="true"
android:visibility="invisible"/>
- 代码中播放、取消动画
animationView.playAnimation(); //播放动画
animationView.cancelAnimation(); //取消动画