首页 > 解决方案 > Picasso 无法在 Android 中使用可绘制资源

问题描述

ImageView img = findViewById(R.id.img);
int resId = R.drawable.coffee;
Picasso.get().load(resId).into(img);

为什么它不起作用。但以下工作正常:

ImageView img = findViewById(R.id.img);
String path= "https://images.pexels.com/photos/434213/pexels-photo-434213.jpeg";
Picasso.get().load(path).into(img);

标签: androidpicasso

解决方案


尝试使用以下代码(thisis context):

Picasso.with(this)
.load(R.drawable.coffee)
.into(img);

你也可以摆脱毕加索:

img.setImageResource(R.drawable.coffee);

推荐阅读