我使用Picasso将我公司CDN中的图像加载到ImageView:
ImageView imgView;
//...
Picasso.with(context).load(Uri.parse(url)).into(imgView);
Run Code Online (Sandbox Code Playgroud)
但现在我需要加载图像作为布局背景:
RelativeLayout theLayout;
//...
Picasso.with(context).load(Uri.parse(url)).into(...);
Run Code Online (Sandbox Code Playgroud)
毕加索有可能吗?如果没有,我应该使用ImageView而不是Relativelayout?
Picasso.with(getActivity()).load(your url).into(new Target(){
@Override
public void onBitmapLoaded(Bitmap bitmap, LoadedFrom from) {
yourlayout.setBackground(new BitmapDrawable(context.getResources(), bitmap));
}
Run Code Online (Sandbox Code Playgroud)
编辑:
您可能还需要重写以下方法
@Override
public void onBitmapFailed(final Drawable errorDrawable) {
Log.e("TAG", "Failed");
}
@Override
public void onPrepareLoad(final Drawable placeHolderDrawable) {
Log.e("TAG", "Prepare Load");
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1384 次 |
| 最近记录: |