【问题标题】:Retreiving multiple images from firebase using Picasso Library and caching them使用 Picasso 库从 firebase 检索多个图像并捕获它们
【发布时间】:2017-06-01 11:06:57
【问题描述】:

我正在开发一个应用程序,我需要首先从 Firebase 检索所有图像,然后以 5 秒的间隔一张一张地显示在图像视图中。大多数时候图像将保持不变,所以我想要缓存这些图像,如果用户离线,则使用缓存的图像并在 imageview 中显示。 但问题是我只得到了毕加索库的以下代码,其中图像直接显示在图像视图上

Picasso.with(RetreivingImageFirebase.this)
                .load("https://firebasestorage.googleapis.com/v0/b/yavatmalindicatorserver.appspot.com/o/Photos%2F22268?alt=media&token=a71e00eb-c453-4803-80d1-9d769037ab46")
                .fit()
                .centerCrop()
                .into(mImageView); 

我需要先保存所有图像,然后一张一张地显示。我已经搜索了有关堆栈溢出的类似问题,但没有一个显示正确的方法。请帮忙

【问题讨论】:

    标签: android caching firebase picasso firebase-storage


    【解决方案1】:

    您正在寻找RequestCreator.fetch

    public void fetch()

    在没有 ImageView 或 Target 的情况下异步完成请求。 当您想用图像预热缓存时,这很有用。笔记: 从任何线程调用此方法都是安全的。

    例如

    Picasso.with(context)
      .load(url)
      .fit()
      .centerCrop()
      .fetch();
    

    【讨论】:

    • 使用 'fetch() 后图像存储在哪里我的意思是如何处理该图像,因为 fetch() 的返回类型为 void
    • 毕加索管理自己的缓存。下次当您尝试将相同的图像 URL 加载到 ImageView 时,它将使用缓存。
    • 使用Picasso.setIndicatorsEnabled(true)查看是否正在使用缓存。
    • Sangharsh 因为我想在使用 fetch() 后从 firebase 检索多个图像,我应该使用什么来将这些图像显示到 ImageView 中。这是我没有得到的主要问题
    • 循环获取所有图像。现在正常使用 Picasso(就像您在没有缓存的情况下使用的那样)在 ImageView 中显示适当的图像。 Picasso 将在进行任何网络调用之前检查其缓存
    猜你喜欢
    • 2020-04-22
    • 2019-07-24
    • 2019-04-08
    • 2017-03-13
    • 2019-06-11
    • 1970-01-01
    • 2020-10-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多