如何在Android Studio的自定义进度对话框中使用Lottie

问题描述

如何在自定义进度对话框中使用抽奖动画。

我知道如何通过抽签实现自定义进度栏,但是我需要进度对话框。

我有json格式的动画。但我不知道如何进行自定义进度对话框。 在gradle中,我写这行

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

和新班级

    import android.app.ProgressDialog;
import android.content.Context;
import android.view.animation.Animation;

public class MyProgressDialog extends ProgressDialog {

    public MyProgressDialog(Context context) {
        super(context,R.style.NewDialog);

        // Todo Auto-generated constructor stub
    }

}

我找到了这部影片,但由kotlin编码。我想使用Java

https://www.youtube.com/watch?v=ZcR6AMNIagU

解决方法

我找到了解决方法

1-为新设计制作一个xml布局。 “ loading.json”是资产文件夹中动画的json格式。

    <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="100dp"
    android:layout_height="100dp"
    >

    <com.airbnb.lottie.LottieAnimationView
        android:id="@+id/progressAnimationView"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_centerInParent="true"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:lottie_autoPlay="true"
        app:lottie_fileName="loading.json"
        app:lottie_loop="true" />

</androidx.constraintlayout.widget.ConstraintLayout>

2-创建新的Java类

public class lottiedialogfragment extends Dialog {
public lottiedialogfragment(Context context) {
    super(context);

    WindowManager.LayoutParams wlmp = getWindow().getAttributes();

    wlmp.gravity = Gravity.CENTER_HORIZONTAL;
    getWindow().setAttributes(wlmp);
    getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    setTitle(null);
    setCancelable(false);
    setOnCancelListener(null);
    View view = LayoutInflater.from(context).inflate(
            R.layout.dialog_lottie,null);
    setContentView(view);
}

}

主要活动中的3个通话对话框

 final lottiedialogfragment lottie=new lottiedialogfragment(this);
    lottie.show();