Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android url中的LinearLayout setBackgroundDrawable位图_Android_Image_Bitmap_Android Linearlayout_Deprecated - Fatal编程技术网

Android url中的LinearLayout setBackgroundDrawable位图

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

我正在尝试将URL中的背景图像设置为带有位图的线性布局,但方法
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()
替换。