Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Space Between CardView

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">
like image 804
user6730398 Avatar asked Aug 21 '16 17:08

user6730398


People also ask

Is CardView a layout?

CardView is a new widget in Android that can be used to display any sort of data by providing a rounded corner layout along with a specific elevation.

How do I customize my CardView?

Customized CardView First, add a CardView dependency to the application-level build. gradle file. Then create a drawable background for the cards. For that, create a new drawable resource file inside the drawable folder.

What is cardUseCompatPadding?

What is cardUseCompatPadding? For a more consistent UI, use cardUseCompatPadding=true. CardView adds additional padding to draw shadows on platforms before Lollipop. This may cause Cards to have different sizes between Lollipop and before Lollipop.


1 Answers

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.
like image 135
astone Avatar answered Oct 20 '22 08:10

astone