使用毕加索设置背景资源 [英] Set background resource using Picasso

查看:266
本文介绍了使用毕加索设置背景资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道毕加索是图像发挥真棒库。

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

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

本code I可以将图像加载到图像视图。

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

但是,有可能设置一个背景资源,使用毕加索

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

推荐答案

的<一个href=\"https://github.com/square/picasso/blob/master/picasso/src/main/java/com/squareup/picasso/RequestCreator.java#L276\">Javadoc对于毕加索的 RequestCreator 类有下面的例子:

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);
    }
}

这篇关于使用毕加索设置背景资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆