Set Background Resource Using Picasso

I know that Picasso is an amazing library for reproducing images.

Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView); 

With this code, I can load an image into an image.

But is it possible to set a background resource using Picasso?

+7
android picasso
source share
2 answers

The javadoc for the Picasso RequestCreator class has the following example:

 public class ProfileView extends FrameLayout implements Target { @Override public void onBitmapLoaded(Bitmap bitmap, LoadedFrom from) { setBackgroundDrawable(new BitmapDrawable(bitmap)); } @Override public void onBitmapFailed() { setBackgroundResource(R.drawable.profile_error); } } 
+12
source share

I just had work with the Picasso library, I tried to set the image as the background. The Picasso library has greatly simplified this, there is a method called "FIT ()" that will do the job for you.

One magical line from Picasso -

  Picasso.with(context).load(mImageURLS.get(position)) .fit().placeholder(R.drawable.rtrt).into(mImageDownloader); 

.fit () does the trick, thanks.

+1
source share

All Articles