Lottie动画学习(Kotlin)

最近一直在学习kotlin,又接触到 Lottie 动画,网上是Java写的 Lottie动画,我用kotlin写了一边,发现了一写问题。总结一下

Lottie学习文章

Lottie for Android GitHub

Lottie,简单的说,流程就是(Android为例):UI设计给出动画的 Json 文件,放到项目中,加载,展示动画。

特别说明一下:Lottie 2.8.0,对应的最小SDK,一定要 大于等于16(Android 4.1)。现在很少有低于4.1了吧,注意下就好

我网上找了个动画对应的Json

出自文章:Lottie开源动画库介绍与使用示例

现在,开始使用:
这里,我先讲一下Java的使用,很简单:
1、我项目中,是用的 androidx

implementation "com.airbnb.android:lottie:2.8.0"

2、res文件夹下,创建raw文件夹,然后,创建一个:hello_world.json 文件
(上面提到的,学习文章中,有这么一句:建议使用 res/raw,因为可以对动画通过 R 文件使用静态引用,而不只是使用字符串名称)
3、把上面提到的,动画对应的 json,复制到 hello_world.json 文件中
4、布局文件:

<?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=".MainActivity">

    <com.airbnb.lottie.LottieAnimationView
        android:background="#55ff0000"
        android:id="@+id/animation_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        app:lottie_loop="true"
        app:lottie_rawRes="@raw/hello_world" />

</RelativeLayout>

5、代码中使用:

	private 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值