I tried the same thing, but none of the suggested solutions helped me.
The only thing that worked was:
1) Create your own background resource (for example, a rectangular shape) with rounded corners.
2) set this custom background using the command -
cardView = view.findViewById(R.id.card_view2); cardView.setBackgroundResource(R.drawable.card_view_bg);
worked great for me! Hope this helps you.
The XML layout I made with the upper left and lower right radius.
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="@color/white" /> <corners android:topLeftRadius="18dp" android:bottomRightRadius="18dp" /> </shape>
In your case, you only need to change topLeftRadius as well as topRightRadius.
Ankit deshmukh
source share