抽奖动画不起作用

Gbe*_*a A 1 android lottie-android lottie

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

Nov*_*cas 8

通过以下步骤使用乐透动画:

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

dependencies {  
compile 'com.airbnb.android:lottie:2.2.0'
}
Run Code Online (Sandbox Code Playgroud)

将视图添加到您的布局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" />
Run Code Online (Sandbox Code Playgroud)

在您的“活动”或“片段”初始化视图中:

private LottieAnimationView animationView;
animationView = (LottieAnimationView) findViewById(R.id.animation_view);
Run Code Online (Sandbox Code Playgroud)

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

animationView.playAnimation();
animationView.cancelAnimation();
Run Code Online (Sandbox Code Playgroud)