[英]Gif loading with random background
I am trying to load gif in AlertDialog
but it's with background 我正在尝试在
AlertDialog
加载gif,但它具有背景
I am getting this : 我得到这个:
this is my layout file 这是我的布局文件
<?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>
my code for load gif 我的代码加载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();
I am using glide for show gif 我正在使用滑翔表演gif
implementation 'com.github.bumptech.glide:glide:3.7.0'
You will get output like this 您将得到这样的输出
try to use this library 尝试使用这个库
compile 'com.kaopiz:kprogresshud:1.1.0'
and add this one also 并添加这个
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();
This will definitely give you the desired output. 这肯定会给您所需的输出。
Use Dialog instead of aleartDialog 使用对话框而不是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();
and in style.xml add this style 并在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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.