CardView之间的间距

12

我需要在 CardView 之间添加空格。

我尝试使用 card_view:cardUseCompatPadding,但它并不起作用。有任何帮助吗?

<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">

常规的填充/边距怎么样?这取决于您想要添加空间的位置。 - Vucko
2个回答

15
android:layout_marginBottom="4dp"  //4dp is recommended

1
我尝试下面的代码。
<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. 无论在layout_marginBottom中设置什么值,Android始终在两个卡片视图之间留有一点空间。我认为layout_marginBottom不影响空间的大小。
  2. card_view:cardUseCompatPadding应该设置为true。
  3. card_view:cardPreventCornerOverlap应该设置为true以影响card_view:cardCornerRadius,而cardCornerRadius的不同值会导致两个卡片视图之间的不同空间。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接