<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.activity.SplashActivity">
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/animationView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:lottie_rawRes="@raw/flower"
app:lottie_autoPlay="true"
app:lottie_loop="true"/>
</RelativeLayout>
今天在项目中看到LottieAnimationView 做的APP启动动画,找了一下资料,学习了
Lottie开源库地址:一个集Android、Ios、React Native与Web平台
首先这个Json 文件是怎么做出来 的呢?
他是通过AE自动生成的,具体可以参考下面文章,关于AE讲的比较详细 AE制作json文件格式动画以及lottie开源库的使用_Android_jiang的博客-CSDN博客_json动画制作
JSON动画库可下载:Featured animations from our community
- 引入库
compile 'com.airbnb.android:lottie:4.2.1'
2 .创建assets文件夹,将json文件放入其中。
3 . 在XML中引用控制
控件常用属性
app:lottie_fileName="likeanim.json" 加载json的文件名
app:lottie_loop="true" 是否循环播放
app:lottie_autoPlay="true" 是否自动播放
JAVA代码控制:
LottieAnimationView lottieLike= (LottieAnimationView) findViewById(R.id.animation_view);
lottieLike.setAnimation("data.json");
lottieLike.loop(true);
lottieLike.playAnimation(); //播放
lottieLike.pauseAnimation(); //暂停
lottieLike.cancelAnimation(); //取消
lottieLike.getDuration(); //获取动画时长
lottieLike.addAnimatorListener(new Animator.AnimatorListener() { //添加动画监听
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)