首页 > 解决方案 > 从 Firebase 存储设置 imageView

问题描述

鉴于我已经拥有用户上传图像的 url,如何直接从 Firebase 将图像设置为 imageView?

标签: androidfirebaseandroid-imageviewfirebase-storage

解决方案


如果您在客户端有可用的图像 URL。实现 GLIDE并将 URL 和 ImageView 传递给 Glide。它将负责向客户显示图像。

ImageView imageView = findViewById(R.id.imageView_ID);

RequestOptions requestOption = new RequestOptions()
        .placeholder(R.drawable.placeholder)
                .error(R.drawable.ic_error_1)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .priority(Priority.HIGH)
                .dontAnimate()
                .dontTransform()

new Glide
    .with(mcontext)
        .load("https://placeholder.com/img/products/imageurl.png")
        .apply(requestOption)
        .thumbnail(0.1f)
        .into(imageView)

添加依赖实现 'com.github.bumptech.glide:glide:4.8.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'


推荐阅读