【问题标题】:populating array with images from a Firebase storage folder使用 Firebase 存储文件夹中的图像填充数组
【发布时间】:2018-10-15 03:40:34
【问题描述】:

所以我设法让我的 Android 应用同时使用 Firebase 和 Glide,并且我能够将 Firebase 中的单个图像加载到 ImageView 中,如下所示:

imageview1;

imageview1 = (ImageView)findViewById(R.id.ivTest);
String url1 = "https://firebasestorage.googleapis.com/v0/b/zxtrix-e017d.appspot.com/o/fullsize%2Falligator.jpg?alt=media&token=1b85f1c4-4133-41d8-a65f-eg2e263g0403";
Glide.with(getApplicationContext())
     .load(url1)
     .into(imageview1);

但是,我目前正在像这样从 /res/ 文件夹中加载一组图像,我想更改它以便从 Firebase 加载。

Integer[] ApocImages =  {R.drawable.image1, R.drawable.image2, R.drawable.image3, R.drawable.image4,
        R.drawable.image5, R.drawable.image6, R.drawable.image7, R.drawable.image8,
        R.drawable.image9, R.drawable.image10, R.drawable.image11, R.drawable.image12,
        R.drawable.image13, R.drawable.image14, R.drawable.image15, R.drawable.image16};

我已将 /res/ 文件夹中的所有图片上传到我的 Firebase 应用存储区。

我现在如何将它们从 Firebase 加载到我的数组中?

谢谢!

【问题讨论】:

    标签: java android firebase android-glide


    【解决方案1】:

    您可以制作一个与您制作的 drawable 相同的 URL 数组。

    String[] url =  {"https://firebasestorage.googleapis.com/v0/b/zxtrix-e017d.appspot.com/o/fullsize%2Falligator.jpg?alt=media&token=1b85f1c4-4133-41d8-a65f-eg2e263g0403",
    "https://firebasestorage.googleapis.com/v0/b/zxtrix-e017d.appspot.com/o/fullsize%2Falligator.jpg?alt=media&token=1b85f1c4-4133-41d8-a65f-eg2e263g0403",
    "https://firebasestorage.googleapis.com/v0/b/zxtrix-e017d.appspot.com/o/fullsize%2Falligator.jpg?alt=media&token=1b85f1c4-4133-41d8-a65f-eg2e263g0403"}; 
    

    在此之后,设置for循环

    for (int i=0; i<url.size; i++) {
        Glide.with(getApplicationContext())
             .load(url.get(i))
             .into(imageview1);
    }
    

    【讨论】:

      猜你喜欢
      • 2018-10-02
      • 2019-09-07
      • 2020-11-01
      • 1970-01-01
      • 2016-09-28
      • 2020-07-04
      • 1970-01-01
      • 2018-11-22
      • 2021-12-28
      相关资源
      最近更新 更多