Search code examples
androidimageviewcardview

Image not show when it is in Cardvew


Below is my code:

<androidx.cardview.widget.CardView
        android:id="@+id/cv_back"
        android:layout_width="@dimen/walletFuncFrameSize"
        android:layout_height="@dimen/walletFuncFrameSize"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_marginTop="24dp"
        android:layout_marginStart="24dp"
        app:cardCornerRadius="250dp">

        <androidx.cardview.widget.CardView
            android:layout_width="@dimen/walletFuncSize"
            android:layout_height="@dimen/walletFuncSize"
            app:cardCornerRadius="250dp"
            android:layout_gravity="center">

            <ImageView
                android:layout_width="@dimen/walletFuncImageSize"
                android:layout_height="@dimen/walletFuncImageSize"
                android:background="@drawable/back"
                android:scaleType="centerCrop"
                android:layout_gravity="center" />

        </androidx.cardview.widget.CardView>
    </androidx.cardview.widget.CardView>

When I test with my Android 10 phone, it works and no problem. But when I test with my Android 8.0 phone, then the image doesn't show.

I tried to remove all cardview but keep imageView only, and the image finally show.

Does anyone know how to fix this problem?

I also tried:

  1. src and srcCompat and background of ImageView
  2. Change both androidx.cardview.widget.CardView to com.google.android.material.card.MaterialCardView
  3. Remove one CardView

Solution

  • Try removing the radius from the inner card view and/or both. if you see the image then u need to decrease the radius or increase the card view size.

    the ImageView is not showing because you have too much radius in both of your card views and the card views are probably not big enough so radius overlaps your image.