我正在尝试在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来显示gif
implementation 'com.github.bumptech.glide:glide:3.7.0'
答案 0 :(得分: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();
这肯定会为您提供所需的输出。
答案 1 :(得分:0)
使用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>