【问题标题】:Android - Glide adds white background to a gif with transparent backgroundAndroid - Glide 为具有透明背景的 gif 添加白色背景
【发布时间】: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


【解决方案1】:

我刚刚弄明白了。我删除了在 ViewDialog 类中添加这一行的白色背景

dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-21
    • 2015-12-11
    • 2012-07-26
    • 2013-11-25
    • 2013-04-03
    • 1970-01-01
    • 2019-11-18
    相关资源
    最近更新 更多