Search code examples
androidxmlandroid-layoutandroid-cardview

Card View with round corner API 27


Below this is my code :

<androidx.cardview.widget.CardView
    android:layout_width="78dp"
    android:layout_height="78dp"
    android:layout_gravity="center"
    app:cardBackgroundColor="?colorSecondary"
    app:cardCornerRadius="250dp">

    <ImageView
        android:id="@+id/customer_image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="@string/content_description"
        android:scaleType="centerCrop"
        android:src="@drawable/ic_no_picture" />

</androidx.cardview.widget.CardView>

It works perfectly with API 30/29/28 but for API 27 i just have an empty CardView. Do you have any idea ?


Solution

  • I just found a way to fix my problem, with API 27 to have circular image with cardView you have to put cardCornerRadius to a maximum of width / height. In my example i just write app:cardCornerRadius="39dp" and it works perfectly.