How to define margin of CardView

点点圈 提交于 2020-01-01 12:12:12

问题


What is the default margin of Support CardView so I can define margin for my situation?

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

回答1:


How to define margin of CardView?

Use attribute android:layout_marginLeft, android:layout_marginRight, android:layout_marginTop and android:layout_marginBottom to define CardView margins.

What is the default margin of Support CardView?

Here is the CardView Documentation. Also see the Design Guidelines.

FYI, Use attribute card_view:cardUseCompatPadding="false" to remove inner padding inside CardView.




回答2:


I also came up with the same problem. It didn't work even though I added android:layout_marginBottom .

But I found the solution. Your CardView should be inside the RelativeLayout. Then android:layout_marginBottom and android:layout_marginTop will work as expected.



来源:https://stackoverflow.com/questions/43525160/how-to-define-margin-of-cardview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!