我可以将 RelativeLayout 的背景设置为不同于 Android Studio 中的可绘制对象吗?
Can I set the Background of RelativeLayout to something different than a drawable in Android Studio?
我正在尝试使用 .setBackground 方法在 Android Studio 中更改 RelativeLayout 的背景。但它只允许将可绘制资源作为一个值。问题是我使用 picasso 从 imgur 下载图片并将它们加载到 imageview 中,我想使用其中之一作为我的 RelativeLayout 的背景。我在网上到处搜索,但找不到任何东西。是否可以将RelativeLayout的背景设置为非Drawable的imageview的图片内容?
使用Target在RelativeLayout中设置位图
Picasso.with(mContext).
load(url).fit().
into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
relativeLayout.setBackground(new BitmapDrawable(mContext.getResources(), bitmap));
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
});
我正在尝试使用 .setBackground 方法在 Android Studio 中更改 RelativeLayout 的背景。但它只允许将可绘制资源作为一个值。问题是我使用 picasso 从 imgur 下载图片并将它们加载到 imageview 中,我想使用其中之一作为我的 RelativeLayout 的背景。我在网上到处搜索,但找不到任何东西。是否可以将RelativeLayout的背景设置为非Drawable的imageview的图片内容?
使用Target在RelativeLayout中设置位图
Picasso.with(mContext).
load(url).fit().
into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
relativeLayout.setBackground(new BitmapDrawable(mContext.getResources(), bitmap));
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
});