【发布时间】:2021-03-26 04:58:43
【问题描述】:
我正在开发一个自定义加载对话框,它将用于 Android 应用程序的每个活动。 gif 具有透明背景,但是当我使用 de Glide 库加载它时,它会添加白色背景。这是代码:
布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/custom_loading_layout">
<ImageView
android:id="@+id/loading_image_animation"
android:layout_width="80dp"
android:layout_height="80dp" />
</RelativeLayout>
ViewDialog 类,每个活动都会调用它:
public class ViewDialog {
Activity activity;
Dialog dialog;
public ViewDialog(Activity activity) {
this.activity = activity;
}
public void showDialog() {
dialog = new Dialog(activity);
//dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
//...set cancelable false so that it's never get hidden
dialog.setCancelable(false);
//...that's the layout i told you will inflate later
//dialog.setContentView(R.layout.custom_loading_layout);
RelativeLayout contentView = (RelativeLayout) ((Activity) activity)
.getLayoutInflater().inflate(R.layout.custom_loading_layout, null);
dialog.setContentView(contentView);
final ImageView image = (ImageView) contentView.findViewById(R.id.loading_image_animation);
Glide.with(activity).asGif().load(R.raw.wannaplay_loading).diskCacheStrategy(DiskCacheStrategy.RESOURCE).into(image);
dialog.show();
}
//..also create a method which will hide the dialog when some work is done
public void hideDialog(){
dialog.dismiss();
}
}
这是它的样子,它不应该有白色背景 Screenshot
【问题讨论】:
-
@sajjad 我已经尝试过了,它没有用。无花果在 raw 文件夹中,但它不起作用
-
你确定不是你的
dialog/layout背景吗?您可以在dialog之外尝试并确保。 -
@sajjad 我的对话框/布局没有任何背景。我尝试添加
contentView.setBackgroundColor(Color.TRANSPARENT);或contentView.setBackgroundResource(0);但它是一样的 -
标签: android animation loading gif android-glide