【问题标题】:Picasso not working with drawable resource in AndroidPicasso 无法在 Android 中使用可绘制资源
【发布时间】:2019-06-09 13:42:14
【问题描述】:
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);

【问题讨论】:

  • 不工作?先生什么意思?
  • 确保您的可绘制咖啡是有效的。分享日志
  • Picasso.with(<Object of context class>).load(path).into(img);
  • 只是好奇。为什么你甚至需要 Picasso 将可绘制对象加载到图像视图中? setDrawable() 还不够吗?

标签: android picasso


【解决方案1】:

尝试使用以下代码(thiscontext):

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

你也可以摆脱毕加索:

img.setImageResource(R.drawable.coffee);

【讨论】:

    【解决方案2】:

    问题是我通过复制和粘贴直接将图像添加到可绘制对象中。 但是您需要使用 minmap 正确添加它。 您的可绘制资源将在 Picass 中正常工作。

    【讨论】:

      猜你喜欢
      • 2014-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-05
      • 2020-07-20
      • 2015-04-29
      相关资源
      最近更新 更多