【问题标题】:Downloads images from firebase storage从 Firebase 存储下载图像
【发布时间】:2016-12-28 01:59:14
【问题描述】:

我正在开发一个使用 firebase 的应用程序,它使用 glide 将图像从 firebase 存储读取到 listview 中。 您知道将图像下载到列表视图项中的最佳方法是什么吗?

【问题讨论】:

  • 在 Google I/O 的 Zero to App talk 中,我们在 Android 应用程序中完全使用了该设置。查看code for that app 以开始使用。
  • 谢谢。但我的意思是,在我的应用程序中,我想显示应用程序附带的照片,这些照片已经在 firebase 存储中,而不是用户上传的照片。您知道在这种情况下从存储中读取的最佳做法是什么吗?

标签: android firebase android-glide firebase-storage


【解决方案1】:

如果你使用 glide,你可以用它来填充 ListView 中的 ImageView。 Glide 有方法into

例如

  final ImageView myImageView;

  Glide
    .with(myFragment)
    .load(url)
    .centerCrop()
    .placeholder(R.drawable.loading_spinner)
    .crossFade()
    .into(myImageView);

【讨论】:

    【解决方案2】:

    我不熟悉 Firebase 存储,但我想当您将图像上传到此平台时,他们会为您提供一个 URL 以便访问此资源。好吧,如果这是正确的,请在您的适配器类中为 ListView 尝试以下代码:

    ImageView img = (ImagenView)findViewbyid(R.id.myimageview);
    String url = "http://..."; //Firebase URL to the picture
    
    Glide.with(yourActivity).load(url).into(img);
    

    别忘了用 Glide 路径修改你的 gradle 文件。

    repositories {
        mavenCentral()
    }
    
    dependencies {
        compile 'com.github.bumptech.glide:glide:3.7.0'
        compile 'com.android.support:support-v4:19.1.0'
    }
    

    希望对你有帮助!

    【讨论】:

      【解决方案3】:

      FirebaseUI-Android 库的 0.6.0 版本包括获取 Firebase StorageReference 并使用 Glide 加载图像的功能:

      // Reference to an image file in Firebase Storage
      StorageReference storageReference = ...;
      
      // ImageView in your Activity
      ImageView imageView = ...;
      
      // Load the image using Glide
      Glide.with(this /* context */)
              .using(new FirebaseImageLoader())
              .load(storageReference)
              .into(imageView);
      

      要包含它,只需将compile 'com.firebaseui:firebase-ui-storage:0.6.0' 添加到您的build.gradle

      【讨论】:

      • 如何从 Firebase 获取特定尺寸的图片?
      • 我们目前在 FirebaseUI 中不支持此功能,您需要自己上传调整大小的图像。一种很好的方法是使用 Cloud Functions for Firebase。
      【解决方案4】:

      • 尝试添加应用级依赖

      dependencies { 
      // FirebaseUI Storage only 
      compile 'com.firebaseui:firebase-ui-storage:0.6.0' 
      } 
      

      • 使用下一个代码从 firebase 存储中获取图像

      ImageView imageView = findViewById(R.id.image_view); 
      Glide.with(context) 
                     .using(new FirebaseImageLoader()) 
                     .load(pathReference ) 
                     .into(imageView);
      

      【讨论】:

        猜你喜欢
        • 2017-01-16
        • 2021-05-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-11
        • 2022-01-02
        • 2017-10-01
        相关资源
        最近更新 更多