how to fix CardView Corner radius issue?

Viewed 5691

I'm using below code to create a CardView with corners but it stay rectangular

<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/cardview_id"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    android:clickable="true"
    android:focusable="true"
    android:foreground="?android:attr/selectableItemBackground"
    card_view:cardCornerRadius="6dp">

UPDATE : there was a mistake in my Manifest i just remove this line:

android:hardwareAccelerated="false"

5 Answers

I also had same issue. The issue I found is...

        android:hardwareAccelerated="false"

removed this line from manifests and the issue resolved for me.

I saw nothing wrong with your code, but if it couldn't worked. try to add this:

    app:cardCornerRadius="@dimen/margin_small"
    app:cardElevation="@dimen/margin_small"
    app:cardUseCompatPadding="true"

It worked well for me. And make sure you're runing above API 21.

Try this :

<android.support.v7.widget.CardView 
    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="8dp"
    card_view:cardCornerRadius="4dp">

 </android.support.v7.widget.CardView>

reference link : check here

try it into style.xml

<item name="cardCornerRadius">9dp</item>

or simply put this line in your card view XML

app:cardCornerRadius="9dp"

Try this

<android.support.v7.widget.CardView 
    ...
    card_view:cardCornerRadius="20dp">

 </android.support.v7.widget.CardView>

Perhaps 6dp radius is not noticable. :)

Suggestion

You need not to make many namespaces, you can use app for every attribute.

Just use this

xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardCornerRadius="20dp"
Related