Space Between CardView
Asked Answered
M

2

12

I need to add space between CardView.

I tried to use the card_view:cardUseCompatPadding and it doesn't work. Any help?

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

    <android.support.v7.widget.CardView
        android:id="@+id/all_restaurant_card_view"
        android:layout_width="wrap_content"
        android:layout_height="120dp"

        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        card_view:cardPreventCornerOverlap="true"
        card_view:cardUseCompatPadding="true">
Molehill answered 21/8, 2016 at 17:11 Comment(1)
How about regular padding/margins? Depending on where you want your space added.Sprinkle
O
16
android:layout_marginBottom="4dp"  //4dp is recommended
Overword answered 21/8, 2016 at 17:31 Comment(0)
E
1

I try bellow code.

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:layout_marginBottom="4dp"

    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    card_view:cardPreventCornerOverlap="true"
    card_view:cardUseCompatPadding="true"
    card_view:cardCornerRadius="50dp"
>
  1. whatever value set in layout_marginBottom, android always have a little space between 2 cardviews. I think layout_marginBottom doen't affect the size of space.
  2. card_view:cardUseCompatPadding should set to true.
  3. card_view:cardPreventCornerOverlap should set to true to affect card_view:cardCornerRadius, and different value of cardCornerRadius cause different space between 2 cardviews.
Erminois answered 22/6, 2018 at 2:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.