随机背景的GIF加载

问题描述 投票:1回答:2

我想在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>

我的加载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 for show gif

implementation 'com.github.bumptech.glide:glide:3.7.0'
android gif android-glide
2个回答
0
投票

使用Dialog而不是alertDialog

 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>

0
投票

你会得到这样的输出

enter image description here

尝试使用此库

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();

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

© www.soinside.com 2019 - 2024. All rights reserved.