Detailed explanation of the use of Android third-party libraries Lottie and mmkv

Time:2021-12-4

Android end usage

First, you need to add dependent code under build.gradle of the current project:


implementation 'com.airbnb.android:lottie:2.8.0'

Secondly, Lottie reads the files in assets by default. We need to save the animation file. JSON exported from the design in the app / SRC / main / assets file. If there is no assets file, create a new one, as shown in the following figure:

在这里插入图片描述

Add the images folder in assets and put the pictures needed in JSON into it. Note that the picture name should always be kept in JSON.

Finally, in the layout XML, add:


<com.airbnb.lottie.LottieAnimationView
        android:id="@+id/lottie_layer_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:lottie_autoPlay="true"
        app:lottie_fileName="immersive_feeling_create_gradients.json"
        app:lottie_imageAssetsFolder="images"
        app:lottie_loop="true" />

lottie_ Filename: indicates the JSON animation file stored in the local assets file
lottie_ Loop: indicates that the animation is executed in a loop
lottie_ Autoplay: indicates that the animation is played automatically
lottie_ Imageassetsfolder: indicates the folder of pictures that support animation
Common methods:
Animationview. Isanimating(): whether the animation is playing;
Animationview. Playanimation(): play animation;
Animationview. Pauseanimation(): pause animation;
Animationview. Cancelanimation(): cancels animation;
Animationview. Setprogress (Progress): set the progress. The progress range is 0 ~ 1;
Animationview.setminandmaxprogress (min, max): set the playback range, 0 ~ 1.

mmkv

Mmkv is a high-performance general-purpose key value component based on MMAP, developed by wechat team. It is similar to a small database and can store some information. It is very simple to use without any configuration, and all changes take effect immediately.

First, you need to add dependent code under build.gradle of the current project:


implementation 'com.tencent:mmkv-static:1.0.23'

Secondly, declare and instance mmkv


MMKV.initialize(this);
MMKV kv = MMKV.defaultMMKV();

Subsequently, the information is stored


kv.encode("bool", true);
kv.encode("int", 1);
kv.encode("string", "Hello world!");

Finally, take out the information


boolean bValue = kv.decodeBool("bool");
int iValue = kv.decodeInt("int");
String str = kv.decodeString("string");

This is the end of this article about the use of Android third-party libraries Lottie and mmkv. For more information about the use of Android third-party libraries Lottie and mmkv, please search the previous articles of developeppaer or continue to browse the relevant articles below. I hope you will support developeppaer in the future!