Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lottie animation slow android

I'm using Airbnb's new library, 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

like image 365
Javier Ventajas Hernández Avatar asked Mar 08 '17 10:03

Javier Ventajas Hernández


People also ask

How can I increase the speed of my Lottie animation?

You can use the SetSpeed action to a value between 1 and higher to make it faster. So 1 is normal speed, and 2 is faster and 3 is even faster. Any value between 0 and 1 will slow down the animation speed.

Do Lottie animations work on mobile?

Lottie is a library for Android, iOS, Web, and Windows that parses Adobe After Effects animations exported as json with Bodymovin and renders them natively on mobile and on the web! The above animation was created in After Effects, and can be rendered natively across all platforms with a simple json file.

Is Lottie better than GIF?

Ultimately, when you load the page, the loading speed matters, which makes Lottie a reasonable choice. These files can be easily used on iOS and Android. On the other hand, the GIF files are only 4-5 seconds long for 5 MB, which is a lot in real life and practically impossible to load every time.

How do I use Lottie on Android?

Step 1: Add this dependency into the App level gradle module of the project and then sync the gradle with the project. This library enables us to use Lottie's animations: Java.


Video Answer


1 Answers

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

like image 75
Nick Cardoso Avatar answered Sep 21 '22 05:09

Nick Cardoso