How Remove Unnecessary Space Between Cards in Recyclerview

Remove extra spaces between CardViews in RecyclerView

If you want to get rid of it all together you may use a negative for the contentPadding attribute of the CardView such as:

card_view:contentPadding="-8dp"

Adding negative margins should work.

Unable to remove extra space between CardView items - Scrollable RecyclerView

I have not implemented a RecyclerView, however I have replicated two rows in a linear layout, minus the padding from your original question:

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


<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:background="#303030"
android:id="@+id/cv1"
card_view:cardElevation="5dp"
android:foreground="?android:attr/selectableItemBackground"
xmlns:android="http://schemas.android.com/apk/res/android">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_margin="4dp"
android:longClickable="true"
android:background="#303030">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/person_photo"
android:background="@drawable/vector_red"
android:layout_alignBottom="@+id/txtSub" />


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/txtMain"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/person_photo"
android:layout_toEndOf="@+id/person_photo"
android:elevation="4dp"
android:textSize="20dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/txtSub"
android:layout_below="@+id/txtMain"
android:layout_toRightOf="@+id/person_photo"
android:layout_toEndOf="@+id/person_photo" />

</RelativeLayout>

</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:background="#303030"
android:id="@+id/cv1"
card_view:cardElevation="5dp"
android:foreground="?android:attr/selectableItemBackground"
xmlns:android="http://schemas.android.com/apk/res/android">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_margin="4dp"
android:longClickable="true"
android:background="#303030">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/person_photo"
android:background="@drawable/vector_red"
android:layout_alignBottom="@+id/txtSub" />


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/txtMain"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/person_photo"
android:layout_toEndOf="@+id/person_photo"
android:elevation="4dp"
android:textSize="20dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/txtSub"
android:layout_below="@+id/txtMain"
android:layout_toRightOf="@+id/person_photo"
android:layout_toEndOf="@+id/person_photo" />

</RelativeLayout>

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

</LinearLayout>

Play around with the padding and you will get better results. You can also try adding a background color to your card, then you can get rid of layout margins in your RelativeLayout!

How do I decrease the space between cards in a CardView within a RecyclerView?

Edit these attributes

card_view:cardMaxElevation="1dp"
card_view:cardElevation="1dp"

so full code will be

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

<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="200dp"
card_view:cardCornerRadius="5dp"
card_view:cardMaxElevation="1dp"
card_view:cardElevation="1dp"
card_view:cardBackgroundColor="@color/colorPrimary"
card_view:cardUseCompatPadding="true"
card_view:cardPreventCornerOverlap="false"
>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/card_list">
<ImageView
android:id="@+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:src="@drawable/bag"
android:contentDescription="string/video_thumbnail_description"
android:layout_weight="1"
/>

<TextView
android:id="@+id/video_title_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="lovelksdjslkdjlsdj"
android:layout_weight="3"
/>
</LinearLayout>
</android.support.v7.widget.CardView>

Remove spacing between items in RecyclerView android

just remove the cardview in your layout/cardview_recycler.xml, android puts that spacing that you don't want

<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<mypackagename.ui.view.RecyclingImageView
android:id="@+id/avatar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="@drawable/img_no_avatar" />

<TextView
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:singleLine="true"
android:ellipsize="end"
android:padding="@dimen/spacing"
android:textColor="@color/black"
android:layout_alignParentBottom="true"
android:textSize="@dimen/text_smallest" />
</LinearLayout>

everything else stays as it is



Related Topics



Leave a reply



Submit