Panagiotis Lymperopoulos Panagiotis Lymperopoulos - 2 months ago 15
Android Question

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

       into(new Target() {
                public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                    relativeLayout.setBackground(new BitmapDrawable(mContext.getResources(), bitmap));

                public void onBitmapFailed(Drawable errorDrawable) {


                public void onPrepareLoad(Drawable placeHolderDrawable) {