使用Picasso设置背景资源

Sya*_*m S 8 android picasso

我知道毕加索是一个很棒的图书馆.

Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
Run Code Online (Sandbox Code Playgroud)

使用此代码,我可以将图像加载到图像视图.

但是可以使用Picasso设置后台资源吗?

gnu*_*nuf 12

Picasso 班级的JavadocRequestCreator有以下例子:

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 使用setBackground(new BitmapDrawable(context.getResources(),bitmap)),因为不推荐使用示例中显示的代码. (4认同)