Java – CardView is not working

CardView is not working… here is a solution to the problem.

CardView is not working

I

have a job with RecyclerView and I also use CardView. I’ve worked out all these standard programs (created ViewHolder, implemented the necessary methods), but the problem is that the corners of the CardView are not round. I only get the rectangular corners of the CardView.

Here is the XML code for the Adapter’s “main layout”:

<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"
    android:layout_height="250dp"
    android:layout_margin="15dp"
    card_view:cardElevation="10dp"
    card_view:cardCornerRadius="30dp">

<RelativeLayout
        android:layout_margin="20dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

<TextView
            android:id="@+id/adapterText"
            android:text="@string/textCaption"
            android:layout_alignParentStart="true"
            android:layout_alignParentLeft="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

<TextView
            android:id="@+id/adapterDate"
            android:text="@string/date"
            android:layout_marginTop="10dp"
            android:layout_alignParentStart="true"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/adapterText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

</RelativeLayout>

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

There is another layout with RecyclerView:

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_margin="10dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
        android:id="@+id/contactList"
        android:scrollbars="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </android.support.v7.widget.RecyclerView>

</RelativeLayout>

and initialization of RecyclerView:

@Override
public void onViewCreated(View root, Bundle savedInstanceState) {
    if (root != null) {
        RecyclerView mRecyclerContactList=(RecyclerView)(root.findViewById(R.id.contactList));
        mContactAdapter=new ContactAdapter(getContext(),mContextualMultiMode,mContactList);
        mRecyclerContactList.setAdapter(mContactAdapter);
        RecyclerView.ItemAnimator animator=new DefaultItemAnimator();
        mRecycle

rContactList.setItemAnimator(animator);
            RecyclerView.ItemDecoration mVerticalDecoration=new DividerItemDecoration
                    (getContext(), LinearLayoutManager.VERTICAL);
            mRecyclerContactList.addItemDecoration(mVerticalDecoration);
            mRecyclerContactList.setLayoutManager(new LinearLayoutManager(getContext()));

}

}

Does anyone know how to fix this?

Solution

Cardview as root gives me strange problems. Try using Relativelayout as root.

Related Problems and Solutions