Digvijay
Digvijay

Reputation: 3271

CardView is not showing properly in RecyclerView

I want to show card view in recycler view. I have compiled card view library in gradle file but the problem is card view is not showing there is no elevation and shadow it is showing simple plain view.

Here is my gradle dependencies:

implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0   

Row_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_marginTop="10dp">

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardElevation="3dp"
    app:cardBackgroundColor="#fff"
    app:cardCornerRadius="3dp"
    app:contentPadding="3dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="150dp"
            android:layout_height="140dp"
            android:id="@+id/userPostBook"/>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginTop="20dp"
            android:id="@+id/userBookName"
            android:textSize="18sp"/>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:paddingBottom="5dp"
            android:paddingRight="5dp"
            android:text="DELETE"
            android:id="@+id/delete"
            android:textColor="#fff"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:background="@drawable/delete_button"
            tools:ignore="HardcodedText"
            android:layout_alignParentEnd="true" />

        </RelativeLayout>

    </LinearLayout>

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

This is how it is showing in recyclerview:

enter image description here

As you can see in above screenshot there is no card view is showing in recyclerview. Someone please let me know how can I overcome this issue. Any help would be appreciated.

THANKS

Upvotes: 1

Views: 694

Answers (1)

AskNilesh
AskNilesh

Reputation: 69689

You need to use app:cardUseCompatPadding="true" in your CardView

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardElevation="3dp"
    app:cardUseCompatPadding="true"
    app:cardBackgroundColor="#fff"
    app:cardCornerRadius="3dp"
    app:contentPadding="3dp">

Upvotes: 3

Related Questions