android - 设置添加背景颜色以滑动图像

标签 android background android-glide

我在这种模式下使用 Glide 在 ImageView 中设置 png 图像(带透明胶片):

Glide.with(context).load(url)
                .crossFade()
                .placeholder(R.drawable.no_contest)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into((ImageView)container);

是否可以在不设置ImageView背景颜色的情况下设置图片的背景颜色?

谢谢

最佳答案

LayerDrawable应该使用:

.into(new SimpleTarget<GlideDrawable>() {

    @Override
    public void onResourceReady(GlideDrawable resource,
                                GlideAnimation<? super GlideDrawable> glideAnimation) {
        final ShapeDrawable background = new ShapeDrawable();
        background.getPaint().setColor("color here");
        final Drawable[] layers = {background, resource};

        container.setImageDrawable(new LayerDrawable(layers));
    }
});

关于android - 设置添加背景颜色以滑动图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35683471/

相关文章:

java - 如何在使用 Glide 加载之前解密图像

android - 你如何使用一个加载占位符,它是一个带有图像加载器(如 Glide、Picasso 等)的动画微调器?

android - 可以将 Davlik 移入 Linux 内核以提高性能吗?

android - 如何获取 android webview url 以自动检测 https http 和 www?

html - 为什么我的背景图片不显示?

java - 如何将重复背景图像设置为 JPanel?

c# - 'await' 运算符只能在 Xamarin Android 中的异步方法中使用

java - 检查以毫秒为单位的时间是否是明天

asp.net - CSS 和 ASP.NET 控件

android-glide - 吉尔德 : How check if image is cached by url?