Lottie animation slow android

I am using the new Airbnb library, Lottie , to make animations in my application.

The animation consists of a 70 kb JSON file and a 328 kb image folder. There are 13 small pngs in this folder.

Following the testimony of the GitHub repo, I declare my opinion as follows

<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, according to the corresponding java class, I call:

  mLottieView.setImageAssetsFolder("images"); 

However, I have a problem. The animation is awkward and slow, and my memory usage jumps through the roof. It goes from 13 MB to 89, all this happens in the main stream.

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

thanks

+5
source share
3 answers

The documentation mentions several elements that affect performance

  • If there are no masks or mats in the composition, then the performance and memory overhead should be pretty good.

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

There are also some common problems for Android / mobile devices:

  • When using the combination width="match_parent", height="wrap_content" images will be enlarged. Use a wrapper, wrapper, or fixed size.
  • Alpha on PNG adds extra overhead for processing

If your UI thread does too much work, as you suggest, can you delay the start of the animation? If this parameter is then LottieComposition contains static methods such as LottieComposition.fromJson() .

You can manually adjust your compositions in the background stream (and then optionally create a LottieDrawable and set the composition). After that, you can switch to the UI thread and setComposition (or setImageDrawable) to LottieAnimationView

+4
source

As for your "small images" and memory problems, I already answered a fairly similar question:

A huge surge in memory consumption when using png with a lot of transparent area

Do not confuse the 328kb image folder. In memory, these images take up much more space. And it is for this reason that you have a jump in memory consumption.

Isolation and garbage collection that collects this number of bitmaps during animation will always be followed by delays.

0
source

I solved this problem using these two lines of codes

  final LottieAnimationView animationView = (LottieAnimationView) findViewById(R.id.animation_view); animationView.useExperimentalHardwareAcceleration(true); animationView.enableMergePathsForKitKatAndAbove(true); 
0
source

Source: https://habr.com/ru/post/1265173/


All Articles