Android url中的LinearLayout setBackgroundDrawable位图
我正在尝试将URL中的背景图像设置为带有位图的线性布局,但方法Android url中的LinearLayout setBackgroundDrawable位图,android,image,bitmap,android-linearlayout,deprecated,Android,Image,Bitmap,Android Linearlayout,Deprecated,我正在尝试将URL中的背景图像设置为带有位图的线性布局,但方法BackgroundDrawable()已被弃用,我找不到任何替代方法 private LinearLayout linearLayout; linearLayout = (LinearLayout) findViewById(R.id.layout); Drawable drawableBitmap = new BitmapDrawable(getApplicationContext().getResources(), getBit
BackgroundDrawable()
已被弃用,我找不到任何替代方法
private LinearLayout linearLayout;
linearLayout = (LinearLayout) findViewById(R.id.layout);
Drawable drawableBitmap = new BitmapDrawable(getApplicationContext().getResources(), getBitmapFromURL(url));
linearLayout.setBackgroundDrawable(drawableBitmap);
使用毕加索图书馆
private LinearLayout linearLayout;
linearLayout = (LinearLayout) findViewById(R.id.layout);
ImageView img = new ImageView(this);
Picasso.with(this)
.load(imageUri)
.fit()
.centerCrop()
.into(img, new Callback() {
@Override
public void onSuccess() {
linearLayout.setBackgroundDrawable(img.getDrawable());
}
@Override
public void onError() {
}
});
试试这个解决方案。你的位图在这里
LinearLayout bg = (LinearLayout) findViewById(R.id.linearlayout);
BitmapDrawable ob = new BitmapDrawable(getResources(), bitmap)
bg.setBackground(ob);
API级别16中的
setBackgroundDrawable()
被setBackground()
替换,如中所述。可能重复的FWIW,setBackgroundDrawable()
被API级别16中的setBackground()
替换。