Android studio使用Lottie- 让Android动画实现更简单

来源:互联网 发布:2017中国大学生数据 编辑:程序博客网 时间:2024/05/25 01:35

Lottie是什么?

Lottie是Airbnb开源的一个支持 Android、iOS 以及 ReactNative,利用json文件的方式快速实现动画效果的库。

Lottie项目地址:https://github.com/airbnb/lottie-android

Demo程序的github地址 :https://github.com/fengwenjing/MyLottieDemo

二、Lottie在Android端怎么用?
下面是公司美工的工作
  1. 让设计师使用Adobe 的 After Effects(简称 AE)工具(美工一般都会这个)制作这个动画。
    AE的下载地址可以去官网下载,然后自行破解即可……
  2. 在AE中安装一个叫做Bodymovin的插件。
    下载 bodymovin,解压缩后只需要\build\extension\bodymovin.zxp这个档案就可以


    3.手动安装plugin,以windows系统而言,要先下载 ExMan Command Line tool并解压缩。
    再来把下载的bodymovin压缩后的 bodymovin-master\build\extension 目录下的bodymovin.zxp 这个档案复制进去同一个资料夹。


4.去找cmd,并以系统管理员身分执行。



5.打“cd C:/ExManCmd_win 所在的路径 “,进入ExManCmd的资料夹中



6.接着打 ExManCmd.exe /install bodymovin.zxp 就完成了



7.再来进入AE 后,可以在windows/extentions/bodymovin 找到插件,开启后按下Render 就完成了。 

重点来了,这时会在你选的Destination Folder目录中生成一个json格式的文件,这个 json 文件描述了该动画的一些关键点的坐标以及运动轨迹。


1478641345-4251-svgani7

下面就是苦逼Android程序员应该如何做咯

1.在build.gradle中添加

dependencies {    compile 'com.airbnb.android:lottie:2.2.0'}

2.layout文件中添加

    <com.airbnb.lottie.LottieAnimationView        android:id="@+id/animation_view"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        app:lottie_fileName="hello-world.json"        app:lottie_loop="true"        app:lottie_autoPlay="true" />

3.将你的json文件重命名为xml中lottie_fileName的值,将hello-world.json放入 app/src/main/assets目录中。打包吧!!


请注意:第二步编译打包会出现---error: Error parsing XML: unbound prefix

请参考:http://blog.csdn.net/qq_36255612/article/details/77835658

然后你就会发现奇迹出现了,没有一张图片,没有一个gif,但是动画效果出来了!就是这么简单,就是这么暴力!




原创粉丝点击