android - 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);
解决方案
尝试使用以下代码(this
is context
):
Picasso.with(this)
.load(R.drawable.coffee)
.into(img);
你也可以摆脱毕加索:
img.setImageResource(R.drawable.coffee);
推荐阅读
- python - 使用 BeautifulSoup 和不变的 URL 进行网页抓取
- c# - NSwag:如何在 C# -> Swagger -> C# 客户端中使用自定义值对象类型?
- system-verilog - 随机约束是否可以在子类中,而它已在基类中声明。如果是怎么办?
- node.js - 错误:找不到模块 '.../webpack' Vue js
- c++ - QMediaPlayer 无法在 Window 上播放歌曲
- mysql - SQL GROUP_CONCAT 查询帮助
- java - 在 Android 中使用 ACTION_DIAL 可以同时拨打两个特殊符号
- intellij-idea - 如何使用预提交挂钩使用 IntelliJ 格式格式化代码?
- javascript - 需要在另一个 div 悬停时向 div 添加类
- vue.js - 如何解决在 shopware 中通过 Lightweight 方法创建的 2 个插件之间的冲突?