繁体   English   中英

从Firebase存储下载图像

[英]Downloads images from firebase storage

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

如果使用滑行,则可以使用滑行将其填充到ListView中。 滑翔有方法into

例如

  final ImageView myImageView;

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

我不熟悉Firebase Storage,但是我想当您将图像上传到该平台时,它们会为您提供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'
}

希望能帮助到你!

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

•尝试添加应用程序级别的依赖关系

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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM