Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CardView doesn't work properly

I have a work with the RecyclerView, and I use the CardView as well.I have made all these standards procedures (created the ViewHolder, implemented necessary methods) but the problem is that CardView's corners aren't rounded.I get only rectangular corners of the CardView.

Here is the XML code of 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>

And 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 the 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 anybody know how to solve this issue?

like image 741
nullbyte Avatar asked Apr 20 '26 20:04

nullbyte


1 Answers

Cardview as root causes strange problems to me. Try to use Relativelayout as root.

like image 192
Kai Wang Avatar answered Apr 23 '26 11:04

Kai Wang