Android 学习使用Lottie动画库

Android Lottie动画库

最近工作上面需要所以导入了一个Android的动画库Lottie ,这篇博客主要是为了记载一下这个动画库,以及动画库的简单的用法。

简单的来说下这个lottie动画库
Lottie是适用于Android和iOS的移动库,它可以使用Bodymovin解析以json 格式导出的Adobe After Effects动画,并在移动设备上进行本地渲染!(官方的github上是这么说的)

我这里给上github的地址
https://github.com/airbnb/lottie-android

不要聊了!不要聊了!先上图。
在这里插入图片描述

Lottie优势
1、开发可以不用写动画了,而且是那些复杂的动画。
2、Android, iOS, 和React Native多平台支持。
3、性能好,显示效果完美。

Lottie劣势
1、苦了UI,对AE使用要求高一点, 动画更加依赖设计师

怎么使用
导入动画库,github上面有新的自己去写版本号,我用的是他现在最新的

implementation 'com.airbnb.android:lottie:3.4.1'

把UI给你们的json动画文件放进你的assets文件夹中间
在这里插入图片描述
你如果只是做一下测试没得UI给你整这个json文件的话
这里可以白嫖(Lottie社区)

第一种方式布局里面直接使用就行了

 <com.airbnb.lottie.LottieAnimationView
        android:id="@+id/loading_animation"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal"
        app:lottie_fileName="my_card.json"
        app:lottie_loop="true"
        app:lottie_autoPlay="true"/>
app:lottie_fileName="my_card.json"

这里可以直接设置动画的文件。

第二种方式代码里面设置

LottieAnimationView loading_animation = (LottieAnimationView) findViewById(R.id.loading_animation);
loading_animation.setAnimation("my_card.json");
loading_animation.loop(true);
loading_animation.playAnimation();
loadingAnimation.addAnimatorListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
                MyLoge.addLoge("loadingAnimation","start");
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                MyLoge.addLoge("loadingAnimation","end");
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                MyLoge.addLoge("loadingAnimation","Cancel");
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
                MyLoge.addLoge("loadingAnimation","Repeat");
            }
        });

里面还有很多的方法可以自己去试一试!

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Android中,可以使用Lottie来加载和播放Lottie动画。以下是一些常见的控制Lottie动画的方法: 1. 播放和停止动画 可以使用`playAnimation()`方法来播放动画使用`cancelAnimation()`方法来停止动画。 ```java LottieAnimationView animationView = findViewById(R.id.animation_view); animationView.playAnimation(); // 播放动画 animationView.cancelAnimation(); // 停止动画 ``` 2. 循环播放动画 可以使用`setRepeatCount()`方法来设置动画的循环次数,使用`setRepeatMode()`方法来设置动画的循环模式。 ```java LottieAnimationView animationView = findViewById(R.id.animation_view); animationView.setRepeatCount(LottieDrawable.INFINITE); // 设置无限循环 animationView.setRepeatMode(LottieDrawable.RESTART); // 设置循环模式为重新开始 ``` 3. 动态改变动画速度 可以使用`setSpeed()`方法来设置动画的速度。默认速度为1.0,可以设置为小于1.0的值来减慢速度,或者大于1.0的值来加快速度。 ```java LottieAnimationView animationView = findViewById(R.id.animation_view); animationView.setSpeed(0.5f); // 设置动画速度为原速度的一半 ``` 4. 动画监听器 可以使用`addAnimatorListener()`方法来添加动画监听器,监听动画的各种事件,例如动画开始、结束、重复等。 ```java LottieAnimationView animationView = findViewById(R.id.animation_view); animationView.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) { // 动画重复时执行的操作 } }); ``` 这些方法可以帮助你在Android中控制Lottie动画,让你的应用更加生动有趣。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值