从Firebase存储设置imageView

时间:2018-11-12 08:16:20

标签: android firebase android-imageview firebase-storage

考虑到我已经具有用户上载图像的URL,如何直接从Firebase将图像设置为imageView?

3 个答案:

答案 0 :(得分:0)

  

如果客户端有可用的图像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'       注解处理器'com.github.bumptech.glide:compiler:4.8.0'

答案 1 :(得分:0)

您可以使用图像加载库,例如Glide或Picasso,

首先在依赖项下的build.gradle(Moduke:App)中添加依赖项,

dependencies {
....
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
}

然后在从url中加载图像视图的活动中:

Glide.with(this).load(IMAGE_URL).into(imageView);

IMAGE_URL是图像的Firebase存储URL,而imageView是显示图像的位置。

关注https://bumptech.github.io/glide/以获取更多信息

答案 2 :(得分:-1)

          private CircleImageView uDisplayImage;
  currentFirebaseUser = FirebaseAuth.getInstance().getCurrentUser();
            FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();

            String uId = currentFirebaseUser.getUid();
            myRef = firebaseDatabase.getReference("user").child(uId);
      myRef.addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {



                    image = dataSnapshot.child("image").getValue().toString();


                    if (!image.equals("default")) {

                        Picasso.get().load(image).placeholder(R.drawable.idofcircularview).into(uDisplayImage);
                    }



                }

                @Override
                public void onCancelled(@NonNull DatabaseError databaseError) {
                    Toast.makeText(SattingsActivity.this, "Sorry Data is not found", Toast.LENGTH_SHORT).show();

                }
            });
    implementation 'de.hdodenhof:circleimageview:2.2.0'
        implementation 'com.squareup.picasso:picasso:2.71828'