如何定义CardView的边距

6
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">
2个回答

11

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

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


10

如何定义CardView的边距?

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

Support CardView的默认边距是多少?

这里是CardView文档。还可以查看设计指南

顺便提一下,使用属性card_view:cardUseCompatPadding="false"可以移除CardView内部的内边距。


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