Set background resource using Picasso

左心房为你撑大大i 提交于 2019-12-12 09:37:20

问题


I know Picasso is an awesome library to play with images.

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

with this code i can load an image to an image view.

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


回答1:


The Javadoc for Picasso's 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);
    }
}



回答2:


I just had a work around with the Picasso library, I was attempting to set the image as a background as well. Picasso library made it very easy to do this, there is method by name "FIT()" which will do this job for you.

The one magic line from Picasso is

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

.fit() does the trick, thanks.



来源:https://stackoverflow.com/questions/21066292/set-background-resource-using-picasso

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!