1

如何在 Android 中使用 Lottie 动画?我试过了,但动画没有运行。如何启动 JSON 动画?我想使用自定义加载动画而不是使用常规的圆形进度条。

4

1 回答 1

10

通过以下步骤使用 Lottie 动画:

将 Gradle 依赖项添加到您的应用程序

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

将视图添加到您的布局 XML:

<com.airbnb.lottie.LottieAnimationView
    android:id="@+id/animation_view"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:lottie_fileName="preloader.json"//this is the JSON animation stored in assets folder
    app:lottie_loop="true"
    app:lottie_autoPlay="true" />

在您的 Activity 或 Fragment 中初始化视图:

private LottieAnimationView animationView;
animationView = (LottieAnimationView) findViewById(R.id.animation_view);

使用以下方法播放/取消动画:

animationView.playAnimation();
animationView.cancelAnimation();
于 2017-08-28T18:09:21.967 回答