Gif 加载随机背景

Gif loading with random background

我正在尝试在 AlertDialog 中加载 gif,但它有背景

我收到了:

这是我的布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/lnrMstr"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/lnemoji"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="visible"
        android:layout_gravity="center_horizontal"
        android:gravity="center">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/background_popup"
            android:padding="@dimen/_10sdp">

            <ImageView
                android:id="@+id/imgemoji"
                android:layout_width="@dimen/_100sdp"
                android:layout_height="@dimen/_100sdp" />

        </LinearLayout>

    </LinearLayout>

</LinearLayout>

我的 load gif

代码
 LayoutInflater inflater = getLayoutInflater();
        View alertLayout = inflater.inflate(R.layout.popupdialoggif, null);
        SurfaceView dialogsurface=(SurfaceView)alertLayout.findViewById(R.id.dialogcamerapreview);
        final ImageView emoji=(ImageView) alertLayout.findViewById(R.id.imgemoji);
        final AlertDialog.Builder alert = new AlertDialog.Builder(mContext);
        alert.setView(alertLayout);
        alert.setCancelable(true);
        final AlertDialog dialog = alert.create();
        Glide.with(LoginActivity.this)
                .load(R.drawable.welcome)
                .into(emoji);
       dialog.show();

我正在使用 glide 来显示 gif

implementation 'com.github.bumptech.glide:glide:3.7.0'

你会得到这样的输出

尝试使用这个库

compile 'com.kaopiz:kprogresshud:1.1.0'

并添加这个

compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.10'

    GifImageView imageView = new GifImageView(context);
    GifDrawable gifFromAssets = null;
    GifDrawable gifFromResource = null;
    try {
        gifFromAssets = new GifDrawable(context.getResources(), R.drawable.loader);
    } catch (IOException e) {
        e.printStackTrace();
    }
    imageView.setImageDrawable(gifFromAssets);

    final KProgressHUD progressDialog = new KProgressHUD(context)
            .setCancellable(false)
            .setCustomView(imageView)
            .show();

这一定会给你想要的输出。

使用 Dialog 而不是 aleartDialog

 final Dialog dialog = new Dialog(Main2Activity.this,R.style.mydialog);
    dialog.setContentView(R.layout.fragment_main2);
    final ImageView emoji=(ImageView) alertLayout.findViewById(R.id.imgemoji);

    Glide.with(Main2Activity.this)
            .load(R.drawable.ic_launcher_foreground)
            .into(emoji);
    dialog.show();

并在 style.xml 中添加此样式

<style name="mydialog" parent="@android:style/Theme.Dialog">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowNoTitle">true</item>

</style>