Hot questions for Using Glide in android cardview

Top 10 Java Open Source / Glide / android cardview

Question:

Image on the left is what I'm looking for. If you look carefully at my result on the right you can see the white rounded corners in the bottom, but still no shadows.

I'm using Glide to load some images inside a CardView. I'm not sure exactly what the problem is, but I suspect it's with Glide. In the layout preview the CardView looks as I want it, but not when I load it up in the emulator or real device.

Glide.with(mContext)
            .load(image.getSmall())
            .fitCenter()
            .crossFade()
            .bitmapTransform()
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .into(holder.coverImageView);}

XML

<android.support.v7.widget.CardView 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
card_view:cardCornerRadius="5dp"
card_view:cardElevation="5dp">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="@dimen/card_height"
    android:orientation="vertical"
    android:weightSum="4">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="3.5"
        android:orientation="vertical">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center_horizontal">

            <ImageView
                android:id="@+id/coverImageView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:scaleType="centerCrop" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="left|bottom"
                android:background="@android:drawable/screen_background_dark_transparent"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/titleTextView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:padding="16dp"
                    android:textColor="#FFFFFF"
                    android:textSize="@dimen/text_size"
                    android:textStyle="bold" />
            </LinearLayout>
        </FrameLayout>
    </LinearLayout>
</LinearLayout>


Answer:

The problem wasn't the layout or Glide. A few weeks ago I added this:

android:hardwareAccelerated="false"
android:largeHeap="true"

to my Manifest because of memory management problems (my app would stop responding in Geneymotion). Turns out it created more problems than solving them.

Question:

I'm using firebase database(firebaseUI) for loading text in cardviews recyclerView, but my images are stored in firebase storage. How can I populate my cardviews with a different image for each cardview using Glide?

-Should I only use FirebaseUI database in my code(with Glide) with 'image' as key and the Firebase storage url as value, ie { image:FirebaseStorageURLOfOneImage }? While manually uploading image to firebase storage.

-Or is there a way to use both FirebaseUI database & storage in my code(with Glide), and still load one different image per cardview?


Answer:

I only use FirebaseUI database in my code(with Glide) with 'image' as key and the Firebase storage url as value, ie { image:FirebaseStorageURLOfOneImage }

 public void onBindViewHolder(@NonNull PropertyViewHolder holder,
                                     final int position, @NonNull final Property model) {  
 holder.setPropertyImage(model.getPropertyImage());
}

//...code skipped...

 public void setPropertyImage(String propertyImage){
        ImageView imageView = mView.findViewById(R.id.post_propertyImage);

        // Download directly from StorageReference using Glide
        // (See MyAppGlideModule for Loader registration)
        GlideApp.with(getContext())
                .load(propertyImage)
                .fitCenter()
                .into(imageView);
    }