【问题标题】:Can I use Volley with Picasso?我可以将 Volley 与 Picasso 一起使用吗?
【发布时间】:2015-11-27 14:43:24
【问题描述】:

说我有这个方法

String getURL(){}; // means return a string URL asynchronously 

getURL() 使用 Volley 请求 JSON 对象,GSON 解析该对象以获取图像 URL。

我可以用毕加索做这个吗?

Picasso
    .with()
    .load(getURL())
    .placeholder()
    .into();

毕加索会用实际图像刷新占位符图像吗?

【问题讨论】:

  • 技术困难。不过我会试试的。
  • @the_prole 如果 getURL() 返回一个 JSONObject 那么抱歉,你不能使用它,但是如果 getURL() 返回一个字符串 URL,你可以使用它。跨度>
  • 所以 getUrl() 的返回类型是 void 是吗?你知道 load 需要一个 String 参数吗?这里只是基本的计算机科学。
  • @NigamPatro 所以基本上,我可以通过异步函数获取图像 URL,毕加索会等待它返回一个字符串值?
  • 意思是在Volley的onResponse里面,当你拿到图片的Url,就可以调用Picasso把那个Url加载到imageview中

标签: android android-volley picasso


【解决方案1】:

如您所知,Volley 是异步的,因此在 Volley 请求的onResponse 中,您已成功获取图像的 Url,您可以使用 Picasso 将该 Url 加载到 ImageView 中。

希望这会有所帮助!

【讨论】:

  • 我确实最终尝试了这个here
  • 您的应用似乎存在内存问题?尝试调整图像大小,看看是否可以修复。
【解决方案2】:

我可以在 Volley 的 onResponse 方法中使用 Picasso。

【讨论】:

    猜你喜欢
    • 2015-03-13
    • 2023-03-25
    • 2020-08-04
    • 2018-10-23
    • 2011-02-22
    • 2021-03-16
    • 2016-11-20
    • 2019-01-25
    • 2011-06-11
    相关资源
    最近更新 更多