Загрузка Gif со случайным фоном
Я пытаюсь загрузить gif в AlertDialog
но он с фоном
Я получаю это:
это мой файл макета
<?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 для show gif
implementation 'com.github.bumptech.glide:glide:3.7.0'
Пожалуйста, помогите мне разобраться, что случилось с моим кодом.
Использовать диалог вместо 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>
Вы получите результат следующим образом:
попробуйте использовать эту библиотеку
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();
Это, безусловно, даст вам желаемый результат.