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

Lottie for Android, iOS, and React Native

Lottie is a mobile library for Android and iOS that parses Adobe After Effects animations exported as json with Bodymovin and renders them natively on mobile!

For the first time, designers can create and ship beautiful animations without an engineer painstakingly recreating it by hand. They say a picture is worth 1,000 words so here are 13,000:

All of these animations were created in After Effects, exported with Bodymovin, and rendered natively with no additional engineering effort.

Bodymovin is an After Effects plugin created by Hernan Torrisi that exports After effects files as json and includes a javascript web player. We've built on top of his great work to extend its usage to Android, iOS, and React Native.

Read more about it on our blog post Or get in touch on Twitter (gpeal8) or via lottie@airbnb.com

Other Platforms

  • Web
  • Xamarin
  • NativeScript
  • Appcelerator Titanium

Sample App

You can build the sample app yourself or download it from the Play Store. The sample app includes some built in animations but also allows you to load an animation from internal storage or from a url.

Download

Gradle is the only supported build configuration, so just add the dependency to your project build.gradle file:

发布版

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

测试版

dependencies {  compile 'com.airbnb.android:lottie:2.0.0-beta2'
}

Shipping something with Lottie?

Email us at lottie@airbnb.com and soon we will create a testimonals and use cases page with real world usages of Lottie from around the world.

Using Lottie

Lottie支持ICS(API 14)及以上。 使用它的最简单的方法是LottieAnimationView:

<com.airbnb.lottie.LottieAnimationViewandroid: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" />

或者你可以通过多种方式加载它。 从app / src / main / assets中的json资源:

LottieAnimationView animationView = (LottieAnimationView) findViewById(R.id.animation_view);
animationView.setAnimation("hello-world.json");
animationView.loop(true);
animationView.playAnimation();

此方法将加载文件并在后台解析动画,并在完成后异步开始呈现。

如果你想重用动画,如在列表的每个项目或从网络请求加载它JSONObject:

 LottieAnimationView animationView = (LottieAnimationView) findViewById(R.id.animation_view);...Cancellable compositionCancellable = LottieComposition.Factory.fromJson(getResources(), jsonObject, (composition) -> {animationView.setComposition(composition);animationView.playAnimation();});// Cancel to stop asynchronous loading of composition// compositionCancellable.cancel();

然后可以控制动画或添加监听器:

animationView.addAnimatorUpdateListener((animation) -> {// Do something.
});
animationView.playAnimation();
...
if (animationView.isAnimating()) {// Do something.
}
...
animationView.setProgress(0.5f);
...
// Custom animation speed or duration.
ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f).setDuration(500);
animator.addUpdateListener(animation -> {animationView.setProgress(animation.getAnimatedValue());
});
animator.start();
...
animationView.cancelAnimation();

在引擎盖下,LottieAnimationView使用LottieDrawable来渲染其动画。 如果你需要,你可以直接使用drawable形式:

LottieDrawable drawable = new LottieDrawable();
LottieComposition.Factory.fromAssetFileName(getContext(), "hello-world.json", (composition) -> {drawable.setComposition(composition);
});

如果你的动画将被频繁重用,LottieAnimationView有一个可选的缓存策略内置。UseLottieAnimationView#setAnimation(String,CacheStrategy)。 CacheStrategy可以是Strong,Weak或None,以便让LottieAnimationView保存对加载和解析的动画的强或弱引用。

Image Support

You can animate images if your animation is loaded from assets and your image file is in a subdirectory of assets. Just callsetImageAssetsFolder on LottieAnimationView or LottieDrawable with the relative folder inside of assets and make sure that the images that bodymovin export are in that folder with their names unchanged (should be img_#). If you useLottieDrawable directly, you must call recycleBitmaps when you are done with it.

If you need to provide your own bitmaps if you downloaded them from the network or something, you can provide a delegate to do that:

animationView.setImageAssetDelegate(new ImageAssetDelegate() {@Override public Bitmap fetchBitmap(LottieImageAsset asset) {getBitmap(asset);}});

Supported After Effects Features

Pre-composition


Keyframe Interpolation


  • Linear Interpolation

  • Bezier Interpolation

  • Hold Interpolation

  • Rove Across Time

  • Spatial Bezier

Solids


  • Transform Anchor Point

  • Transform Position

  • Transform Scale

  • Transform Rotation

  • Transform Opacity

Masks


  • Path

  • Opacity

  • Multiple Masks (additive, subtractive, inverted)

Track Mattes


  • Alpha Matte

Parenting


  • Multiple Parenting

  • Nulls

Shape Layers


  • Rectangle (All properties)

  • Ellipse (All properties)

  • Polystar (All properties)

  • Polygon (All properties. Integer point values only.)

  • Path (All properties)

  • Anchor Point

  • Position

  • Scale

  • Rotation

  • Opacity

  • Group Transforms (Anchor point, position, scale etc)

  • Multiple paths in one group

  • Merge paths (off by default and must be explicitly enabled with enableMergePathsForKitKatAndAbove)

Stroke (shape layer)


  • Stroke Color

  • Stroke Opacity

  • Stroke Width

  • Line Cap

  • Dashes

Fill (shape layer)


  • Fill Color

  • Fill Opacity

Trim Paths (shape layer)


  • Trim Paths Start

  • Trim Paths End

  • Trim Paths Offset

Performance and Memory

  1. If the composition has no masks or mattes then the performance and memory overhead should be quite good. No bitmaps are created and most operations are simple canvas draw operations.
  2. If the composition has masks or mattes, offscreen buffers will be used and there will be a performance hit has it gets drawn.
  3. If you are using your animation in a list, it is recommended to use a CacheStrategy in LottieAnimationView.setAnimation(String, CacheStrategy) so the animations do not have to be deserialized every time.

Try it out

Clone this repository and run the LottieSample module to see a bunch of sample animations. The JSON files for them are located in LottieSample/src/main/assets and the original After Effects files are located in /After Effects Samples

The sample app can also load json files at a given url or locally on your device (like Downloads or on your sdcard).

Alternatives

  1. Build animations by hand. Building animations by hand is a huge time commitment for design and engineering across Android and iOS. It's often hard or even impossible to justify spending so much time to get an animation right.
  2. Facebook Keyframes. Keyframes is a wonderful new library from Facebook that they built for reactions. However, Keyframes doesn't support some of Lottie's features such as masks, mattes, trim paths, dash patterns, and more.
  3. Gifs. Gifs are more than double the size of a bodymovin JSON and are rendered at a fixed size that can't be scaled up to match large and high density screens.
  4. Png sequences. Png sequences are even worse than gifs in that their file sizes are often 30-50x the size of the bodymovin json and also can't be scaled up.

Why is it called Lottie?

Lottie is named after a German film director and the foremost pioneer of silhouette animation. Her best known films are The Adventures of Prince Achmed (1926) – the oldest surviving feature-length animated film, preceding Walt Disney's feature-length Snow White and the Seven Dwarfs (1937) by over ten years The art of Lotte Reineger

Contributing

Contributors are more than welcome. Just upload a PR with a description of your changes. Lottie uses Facebook screenshot tests for Android to identify pixel level changes/breakages. Please run ./gradlew --daemon recordMode screenshotTests before uploading a PR to ensure that nothing has broken. Use a Nexus 5 emulator running Lollipop for this. Changed screenshots will show up in your git diff if you have.

If you would like to add more JSON files and screenshot tests, feel free to do so and add the test to LottieTest.

Issues or feature requests?

File github issues for anything that is unexpectedly broken. If an After Effects file is not working, please attach it to your issue. Debugging without the original file is much more difficult.

作者:Brandon Withrow, Gabridl Peal, Leland Richardson 和 Salih AbdulKarim

在以前,在Android,iOS和React Native app上面构建复杂的动画是困难和冗长的过程。你要么不得不为每个尺寸增加大量的图片文件,要么干脆编写数千行不可维护的代码。正因为如此,大多的apps并没有使用动画——尽管这是一个交流想法和创建引人注目的用户体验的强大的工具。一年前,我们就开始改变。

今天,我们很高兴来介绍我们的解决方案。Lottie是一个iOS,Android和React Native库,可以实时渲染After Effects动画,并且允许本地app像静态资源那样轻松地使用动画。Lottie使用名为Bodymovin的开源After Effects的扩展程序导出的JSON文件格式的动画数据。扩展程序与JavaScript player捆绑在一起,可以在web上渲染动画。自从2015年2月开始,Bodymovin的创建者,Hernan Torrisi通过每月为插件添加和改进功能,打造了坚实的基础。我们的团队(Brandon Withrow 在 iOS, Gabriel Peal 在 Android,Leland Richardson 在 React Native,和 我 在体验设计上)在Torrisi的非凡的工作之上开始我们的旅程。

轻松地构建一个丰富的动画

Lottie允许工程师构建一个丰富的动画,而没有艰苦地重写它们的开销。Nick Butcher's的跳跃动画,Bartek Lipinski的汉堡菜单, 和Miroslaw Stanek 的Twitter爱心, 演示它们是多么困难和耗时,它可以用scratch重建动画。使用Lottie,挖掘参考框架,猜测持续时间,手动创建贝赛尔曲线,并重新制作只有一个GIF作为参考的动画将是过去了。现在工程师可以准确地实现设计者的意图,究竟是怎么做的。为了证明它,我们重创建了它们的动画,然后在我们的每个例子中提供了After Effects和JSON文件。

我们的目标是尽可能多地支持After Effects的特性,而不只是简单的图标动画。我们创建了一些其他例子来展示库的灵活性,丰富性和深入的功能集。在例子app中,有用于各种不同种类的动画的源文件,包括基本线条艺术,基于字符的动画,以及具有多个角度和切割的动态logo动画。

我们已经开始在一些界面上使用我们自己的Lottie动画,包括应用内通知,全帧动画插图和在我们的审查流程中。我们计划以一种有趣而有用的方式大大增加我们对动画的使用。

灵活高效的解决方案

Airbnb是一个全球的公司,它支持数百万的顾客和主人,所有在多个平台上播放的灵活动画格式对我们来说是非常重要的。有一些与Lottie类似的库,如Marcus Eckert的Squall和Facebook的Keyframes,但是我们的目标略有不同。Facebook选择了一小部分After Effects的特性进行了支持,因为它们主要集中在响应,但是我们想要尽可能多地支持。至于Squall,Airbnb的设计师组合Lottie来使用它,因为它有一个惊艳的After Effects预览app,这使得它成为我们工作流必要的一部分。然而,它只支持iOS,我们的工程师团队需要一个跨平台的解决方案。

Lottie还在其API中内置了几个功能,使它更多样化和高效。它支持通过网络加载JSON文件,这在A/B测试是非常有用。它还有一个额外的缓存机制,所以频繁使用的动画,比如一个愿望清单的爱心,可以每次加载一个缓存的副本。Lottie动画可以通过使用动画进度功能的手势驱动,并且动画速度可以通过简单改变值来控制。iOS甚至支持在运行时增加额外的本地UI到一个动画中,这可以用于复杂的动画过渡。

除了我们迄今为止的增加所有After Effects特性和API之外,我们还有许多未来的想法。它们包括映射视图到Lottie动画中,使用Lottie控制视图过渡,支持Battle Axe 的 RubberHose,渐变,类型和图像的支持。最难的部分是下一个特性支持应该选择哪一个。

构建社区

作为开源发布一些东西,并不只是把它拿出来做为公共使用。它是一个人跟人之间连接和交流的桥梁。随着我们更接近通过GitHub向设计师和工程师发布Lottie,我们也想确保与动画人员进行连接。

我们受到了创建的9 Squares,Motion Corpse和Animography的启发。所有这三个都聚集了来自世界各地的人,在公共动画项目上合作,他们可能永远不会一起工作。这些项目花费了几个月的工作和很多的组织,各自团队的争论,但是它们无疑对整个动画社区提供了巨大的价值。Motion Corpse 和 Animography 公开分享了After Effects的源文件,它们提供了大量人们怎么工作的深刻的见解。

在他们的合作领导下,我们接触了所有这三个团队,为我们的示例app贡献了动画。我们包括了一个来自 Motion Corpse J.R Canest 创建的动画,来自9 Squares 项目的 Al Boardman 的square之一,和一个使用Animography的Mobilo动画字体的键盘动画,其中有二十多个艺术家的工作。我们希望这些动画社区与强大的工程社区的合并将产生一些特别的东西。

从左到右:Motion Corpse 的 Jr.canest,来自 9 Squares 的 AI Boardman,Animography 的 Mobilo 字体动画

我们想听到你怎么去使用Lottie——不论你是一个设计师,动画师,还是工程师。请随时直接通过 lottie@airbnb.com 带着你的想法,反馈,见解与我们联系。我们很高兴看到当他们开始以我们从未想象的方式使用Lottie时,世界各地的社区将会做些什么。

Lottie for Android 开源动画相关推荐

  1. android jason动画,Android 动画之Lottie动画使用

    Android 动画之Lottie动画使用 一:简介 Lottie是Airbnb开源的一套跨平台的完整解决方案,设计师只需要使用After Effects(简称AE)设计动画之后,使用Lottic提供 ...

  2. android ae动画教程,AE动画转Web代码工具指北-Lottie

    简介 Lottie 是 Airbnb 开源的一套跨平台的完整的动画效果解决方案,设计师可以使用 Adobe After Effects 设计出漂亮的动画之后,使用 Lottic 提供的 Bodymov ...

  3. android 动画开源框架,图文简介非常炫酷的Android开源框架之UI框架

    架构,其又名软件架构,是关于软件整体结构与组件的抽象描述,用于指导大型软件系统各个方面的设计.而软件架构(software architecture)是一系列相关的抽象模式,其是用来指导大型软件系统各 ...

  4. Android 之 Lottie 实现炫酷动画背后的原理

    这是程序亦非猿的第 78 期分享. 作者 l 程序亦非猿 来源 l 程序亦非猿(ID:chengxuyifeiyuan) 转载请联系授权(微信ID:ONE-D-PIECE) 0. 前言 自我在内网发布 ...

  5. android 日历翻页动画,Android开源库合集:轻松实现Android动态,炫目:日历效果...

    前言: 了解过那种动态,炫目的日历效果吗?你知道是怎么 操作的嘛?是否想过,用UI就可以实现,对,也许你说的对,不过UI只是都是动态效果的一部分.那么今天用Annroid开源库,来告诉你android ...

  6. android 动画变成素材,AE技法-把AE动画转换成Android原生动画,撂倒GIF做动画

    4399游戏盒(安卓版APP)项目接手已久,想输出一些小经验分享给大家,以下是写了一个很简单的lottie应用. 一直以来,在 Android.iOS.React Native 上实现一套复杂动画是一 ...

  7. Android 开源项目及网址

    网站: Github:https://github.com/Trinea/android-open-project 泡在网上的日子:http://www.jcodecraeer.com/ 掘金:htt ...

  8. FLutter 官方推荐的二个动画插件lottie和Rive(flare)动画

    FLutter 官方推荐的二个动画插件lottie和rive(flare)动画 lottie 动画:Lottie是一个Android和iOS的移动库,它解析Adobe After Effects动画, ...

  9. Android 图片动画

    1.使用帧动画.但是一个动画需要添加很多张图片,apk体积必然变大,并且还要根据不同的尺寸进行适配. 2.用 Gif.但是使用Gif 占用空间较大,同样需要为各种屏幕尺寸.分辨率做适配,同时原生And ...

最新文章

  1. CentOS7中安装图形界面
  2. 【Java基础】一篇文章读懂多线程
  3. C#Winform将WebBowser控件替换为Chrome内核
  4. 如何在64位Ubuntu16.04下安装java开发环境
  5. VS2017打开低版本的VS MVC架构的项目的时候需要修改的地方
  6. java综合案例_综合实例 - Java House - BlogJava
  7. 使用 jsfl 发布flash IDE 插件
  8. offsetLeft
  9. 留言板删除功能mysql_用PHP写留言板代码时怎样才能实现删除和修改留言的啊?代码是怎样的?...
  10. PDF 文档解除密码
  11. 计算机考研数据库题库
  12. 固定不动的层(兼容IE6)
  13. 织梦系统基本参数php,织梦后台系统基本参数新增的变量数据库修改
  14. linux 网络编程相关知识
  15. Cruise的API简介--Properties篇
  16. redis做浏览历史数据
  17. 解决小程序插槽slot内容显示不对,无论是原生小程序还是uniapp开发的,解决办法如下
  18. cocos2d-x 艺术字
  19. 磁盘满了怎么清理之空间占用分析软件SpaceSniffer
  20. 【Bioinformatics】背曲拇指与 Ehlers-Danlos syndrome

热门文章

  1. 3Dunity游戏项目实战——第一人称射击游戏
  2. Kaggle系列(一):Spaceship Titanic(太空飞船泰坦尼克)
  3. 关于朗讯,北电,上海贝尔阿尔卡特....
  4. 西门子PLC通过RS485串口连接维特智能Modbus协议角度姿态传感器HWT905(4)——多传感器多角度报警
  5. hbase中为何不能向表中插入数据_大数据HBase理论实操面试题
  6. C语言实现简单工厂模式
  7. android图库实现,Android实现简单图库辅助器
  8. jar包无法运行的解决方法
  9. 如何使用solidworks结构焊接模块
  10. linux sd卡启动盘制作工具,fedora liveusb creator linux u盘启动盘制作工具