【问题标题】:how to set image view source dynamically?如何动态设置图像视图源?
【发布时间】:2019-10-03 13:27:58
【问题描述】:

所以我有一个类似于 rest API 的东西,当我调用它时,它会为我提供带有 Json 对象的图像的来源。 我在服务器中有图片的 src,但我不知道如何使用它们。

 rule_op1.setImageResource("https://admin.webeskan.com/upload/lawgroup/"+law0);

其中“https://admin.webeskan.com/upload/lawgroup/”对于所有图像都是相同的,而 law0 是我从 API(Json 对象)获得的字符串之一

【问题讨论】:

  • 使用可以使用 picasso 或 glide 从 url 加载图片
  • 你应该尝试谷歌搜索图像加载库。这些天有很多人。 Glide、Picasso 和 Coil 是我最常接触的三个图书馆。

标签: android json api


【解决方案1】:

使用 Glide 会很有帮助。加载图像非常有效。

https://github.com/codepath/android_guides/wiki/Displaying-Images-with-the-Glide-Library

在您的应用 gradle 中添加以下依赖项。

  implementation 'com.github.bumptech.glide:glide:4.8.0'
  // Glide v4 uses this new annotation processor -- see https://bumptech.github.io/glide/doc/generatedapi.html
  annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'

添加此行以加载图像

GlideApp.with(context)
    .load("https://admin.webeskan.com/upload/lawgroup/"+law0)
    .override(300, 200)
    .into(rule_op1);

【讨论】:

  • 添加依赖后尝试构建?
猜你喜欢
  • 1970-01-01
  • 2016-06-08
  • 2011-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多