-1

I am using Recycler view + card view to show my content but there is unnecessary space between cards how to remove it. I have tried with negative padding but didnt work. Any other solution to this? or there is any bug in my code.

my RecyclerView

<android.support.v7.widget.RecyclerView
    android:layout_marginStart="4dp"
    android:layout_marginEnd="4dp"
    android:id="@+id/reyclerview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/darker_gray"
    android:scrollbars="vertical" />

cardview

<?xml version="1.0" encoding="utf-8"?><android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
app:cardCornerRadius="4dp"
card_view:cardElevation="0dp"
card_view:cardUseCompatPadding="true"
card_view:cardPreventCornerOverlap="false"
android:background="@color/background">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="4dp"
    android:layout_marginStart="4dp">

   //Some Items


</RelativeLayout>

here is the preview of space

enter image description here

Tanveer Ahmed
  • 426
  • 1
  • 4
  • 15

2 Answers2

0

xml :

card_view:cardPreventCornerOverlap="false"

or JAVA

cardView.setPreventCornerOverlap(false)

ref : Android CardView remove padding

Ahmed.ess
  • 265
  • 3
  • 10
0

I have solved it by putting cardview in LinearLayout

<?xml version="1.0" encoding="utf-8"?><LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools">
<android.support.v7.widget.CardView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="4dp"
    android:layout_marginStart="4dp">

    <ImageView
        android:id="@+id/i1"
        android:layout_width="50dp"
        android:layout_height="50dp" />

    <TextView
        android:id="@+id/t1"
        android:layout_width="316dp"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="60dp"
        android:text="Text1"
        android:textSize="15sp" />

    <TextView
        android:id="@+id/t2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/t1"
        android:maxLines="2"
        android:layout_alignStart="@+id/t1"
        android:layout_marginStart="8dp"
        android:layout_marginTop="10dp"
        android:text="Text2"
        android:textSize="12sp" />


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

Tanveer Ahmed
  • 426
  • 1
  • 4
  • 15