【问题标题】:How to define margin of CardView如何定义 CardView 的边距
【发布时间】:2017-09-17 10:05:24
【问题描述】:

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

【问题讨论】:

    标签: java android android-layout cardview


    【解决方案1】:

    我也遇到了同样的问题。即使我添加了android:layout_marginBottom,它也不起作用。

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

    【讨论】:

      【解决方案2】:

      如何定义 CardView 的边距?

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

      支持 CardView 的默认边距是多少?

      这里是CardView Documentation。另请参阅Design Guidelines

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-01-15
        • 2020-03-16
        • 2021-11-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多