如何定义 CardView 的边距

How to define margin of CardView

支持 CardView 的默认边距是多少,以便我可以根据自己的情况定义边距?

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="center_horizontal"
    card_view:cardUseCompatPadding="true"
    card_view:cardCornerRadius="4dp"
    card_view:cardElevation="2dp">

如何定义CardView的边距?

使用属性 android:layout_marginLeftandroid:layout_marginRightandroid:layout_marginTopandroid:layout_marginBottom 定义 CardView 个边距。

支持CardView默认边距是多少?

这里是CardViewDocumentation. Also see the Design Guidelines.

仅供参考, 使用属性 card_view:cardUseCompatPadding="false" 删除 CardView 内的 padding

我也遇到了同样的问题。即使我添加了 android:layout_marginBottom 也没有用。

但我找到了解决方案。 您的 CardView 应该在 RelativeLayout 内。然后 android:layout_marginBottomandroid:layout_marginTop 将按预期工作。