gpt4 book ai didi

layout - 在 Android 中使用 Glide 将背景图像设置为相对布局

转载 作者:行者123 更新时间:2023-12-03 09:40:47 24 4
gpt4 key购买 nike

我如何使用 来做到这一点 Glide ?我要cache图像也可以再次使用它。提前致谢。

最佳答案

您可以像这样在 RelativeLayout 中加载图像。我只是向您展示将图像设置为背景的困难部分。

对于 4.X 之前的 Glide 版本

Glide.with(this).load(imageViewPath).asBitmap().into(new SimpleTarget<Bitmap>(relLayoutWidth, relLayoutHeight) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
Drawable drawable = new BitmapDrawable(context.getResources(), resource);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
yourRelativeLayout.setBackground(drawable);
}
}
});

关于缓存,引用这个页面: Caching and Cache Invalidation .

Glide v4 以后的更新:
GlideApp.with(this).load(R.drawable.backgroundimage).into(new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
yourRelativeLayout.setBackground(resource);
}
}
});

关于layout - 在 Android 中使用 Glide 将背景图像设置为相对布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33971626/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com