【问题标题】:how use lottie in custom progress dialog in android studio如何在android studio的自定义进度对话框中使用lottie
【发布时间】:2020-10-08 09:46:12
【问题描述】:

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

我知道如何使用 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

【问题讨论】:

    标签: android-studio progressdialog lottie


    【解决方案1】:

    我找到了解决办法

    1- 为新设计制作一个 xml 布局。 “loading.json”是asset文件夹中动画的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();
    

    【讨论】:

    • 有隐藏选项吗?
    • 谢谢,萨拉。为我工作。现在我可以添加任何来自 lottie 的自定义进度。
    【解决方案2】:

    您可以使用 LottieDialog 库轻松创建它

    代码会是这样的

    LottieDialog dialog = new LottieDialog(this)
            .setAnimation(R.raw.ripple)
            .setAutoPlayAnimation(true)
            .setDialogHeightPercentage(.2f)
            .setAnimationRepeatCount(LottieDialog.INFINITE)
            .setMessage("Loading...")
            .setMessageColor(orangeColor);
    
    dialog.show();
    

    Github Repo 获取示例和文档:LottieDialog

    最终结果会是这样的

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多