简体   繁体   中英

Can I set the Background of RelativeLayout to something different than a drawable in Android Studio?

I am trying to change the background of my RelativeLayout in Android Studio using the .setBackground method. But it only allows to put as a value a drawable resource. The thing is that I use picasso for downloading pictures from imgur and loading them into an imageview and I want to use one of them as a background for my RelativeLayout. I have searched everywhere online but I can not find anything. Is it possible to set the background of RelativeLayout to the image content of an imageview which is not Drawable?

Use Target to set the bitmap in 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) {

                }
            });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM