android - Picasso 从其 URI 加载可绘制资源

标签 android picasso

我必须将 res 中的 drawable 显示到 ImageView 中。在这个应用程序中,我出于某些原因使用了 picasso 。

在这种情况下,我需要使用 drawable 的 URI 而不是它的 id 来加载它。 为此,这是我的代码:

uri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://"+context.getPackageName()+"/drawable/" + drawableName);

这里使用的drawableName是文件名而不是它们的资源ID。

然后

Picasso.with(context).load(uri).into(imageView);

我确定可绘制的名称是正确的,但 Picasso 似乎不喜欢这个 uri。

最佳答案

如果图像在您的可绘制文件夹中,那么您可以加载它。

Picasso.with(context).load(R.drawable.drawableName).into(imageView);

picasso 会加载它而不需要 Uri。

关于android - Picasso 从其 URI 加载可绘制资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21158425/

相关文章:

Android Picasso Image Viewer - 内存不足异常内存泄漏

java - 安卓 : Picasso is not loading some images

java - Android - 我可以以编程方式覆盖 simple_list_item_1 颜色吗?

java - Android 4.4 及更高版本在重启后不提供持久文件路径

android - java.lang.NullPointerException : Argument must not be null at com. bumptech.glide.util

Android Volley Post 请求 - JsonArrayRequest 的解决方法

android - picasso 的图像方向发生了变化

java - Picasso 不会下载有效的 URL

Android picasso 缓存图片

android - float 操作按钮变形