Using Firebase to store images and bring on Android screen

Asked

Viewed 139 times

0

Good morning, I created a Recyclerview with Cardview to show some photos that are stored in Firebase, but when bringing the photos to the screen the same does not fit in cardView I left the image as android:layout_width="match_parent" android:layout_height="match_parent"I want the picture to take all the space I’ve reserved for her on cardView, someone could help me?

Layout of the Cardview

<?xml version="1.0" encoding="utf-8"?>

<ImageView
    android:id="@+id/imageId"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<LinearLayout
    android:orientation="vertical"
    android:layout_margin="8dp"
    android:layout_gravity="bottom"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/titleId"
        android:text="@string/title"
        android:textSize="18sp"
        android:textColor="@color/text"
        android:textStyle="bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/subTitleId"
        android:text="@string/subtitle"
        android:textColor="@color/text"
        android:textSize="14sp"
        android:layout_marginTop="5dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

Return image in the app inserir a descrição da imagem aqui

My mainactivity, I show only the call from Firebase.

private void prepareCard() {

    databaseReference = firebaseDatabase.getReference("Data");

    databaseReference.addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {

            Item data = dataSnapshot.getValue(Item.class);
            cardList.add(data);
            recyclerView.setAdapter(mAdapter);

        }

1 answer

0

Solved!

I inserted in the Adapter class in the onBindViewHolder method the following line in my case I use Glide .centerCrop()

Ex:`public void onBindViewHolder(Myviewholder Holder, int position) { final item item = cardList.get(position); Holder.title.setText(item.getTitle()); Holder.description.setText(item.getDescription());

    Glide.with(context)
            .load(item.getImage())
            .centerCrop()
            .into(holder.imageView);
}`

Browser other questions tagged

You are not signed in. Login or sign up in order to post.