Lottie动画缓慢的android [英] Lottie animation slow android

查看:1171
本文介绍了Lottie动画缓慢的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Airbnb的新库 Lottie 在我的应用中制作动画./p>

动画由一个70 kb的JSON文件和一个328 kb的图像文件夹组成.此文件夹中有13个小png.

按照GitHub存储库的指示,我这样声明我的观点

    <com.airbnb.lottie.LottieAnimationView
    android:id="@+id/lottie_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:lottie_fileName="animation.json"
    android:layout_gravity="bottom"
    app:lottie_loop="false"
    app:lottie_autoPlay="true"/>

然后在相关的Java类上调用:

        mLottieView.setImageAssetsFolder("images");

但是,我有一个问题.动画笨拙且缓慢,我的内存使用量突然增加.它从13 MB扩展到89 MB,所有这些都发生在主线程上.

你能告诉我是否有办法解决这个问题?

谢谢

解决方案

文档提到了影响性能的几个项目

  • 如果合成没有遮罩或遮罩,那么性能和内存开销应该会很好

  • Png序列甚至比gif差(由于文件大小)

还需要考虑一些通用的Android/移动设备顾虑:

  • 使用width="match_parent", height="wrap_content"组合,图像将放大.使用自动换行,自动换行或固定大小.
  • PNG上的Alpha会增加处理的额外开销

如果您的UI线程按照您的建议进行了过多的工作,您是否可以推迟动画的开始?如果可以的话,则Lottie to make an animation in my app.

The animation consists of a 70 kb JSON file and a 328 kb images folder. There's 13 small pngs in this folder.

Following the GitHub repo's indications, I declare my view like this

    <com.airbnb.lottie.LottieAnimationView
    android:id="@+id/lottie_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:lottie_fileName="animation.json"
    android:layout_gravity="bottom"
    app:lottie_loop="false"
    app:lottie_autoPlay="true"/>

and then, on the pertinent java class I call:

        mLottieView.setImageAssetsFolder("images");

However, I have a problem. The animation is clunky and slow and my memory usage jumps through the roof. It goes from 13 MB to 89, all of this happening on the main thread.

Could you tell me if there is a way to solve this?

Thanks

解决方案

The documentation mentions a few items which affect performance

  • If the composition has no masks or mattes then the performance and memory overhead should be quite good

  • Png sequences are even worse than gifs (due to file sizes)

There are also some generic Android/mobile concerns to consider:

  • With the width="match_parent", height="wrap_content" combination, the images will be scaled up. Use wrap, wrap or a fixed size.
  • Alpha on PNGs adds additional overhead to processing

If your UI thread is doing too much work as you suggest, can you hold off on starting your animation? If that's an option then LottieComposition has static methods such as LottieComposition.fromJson().

You could manually set up your compositions on a background thread (and then optionally create a LottieDrawable and set the composition). Once that's finished you can switch to the UI thread and setComposition (or setImageDrawable) on the LottieAnimationView

这篇关于Lottie动画缓慢的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆