CardView

suggest change

Versions

CardView comes from the v7 support library (cardview-v7). It is not a platform class that shipped with Android 3.0.

Introduction

A FrameLayout with a rounded corner background and shadow.

CardView uses the elevation property on Lollipop for shadows and falls back to a custom emulated shadow implementation on older platforms.

Because rounded-corner clipping is expensive, on platforms before Lollipop CardView does not clip children that intersect the rounded corners. It adds padding to avoid that intersection. Call setPreventCornerOverlap(boolean) to change this behavior.

Parameters

Parameter Details
cardBackgroundColor Background color for CardView.
cardCornerRadius Corner radius for CardView.
cardElevation Elevation for CardView.
cardMaxElevation Maximum elevation for CardView.
cardPreventCornerOverlap On API 20 and earlier, add padding so the card content does not intersect the rounded corners.
cardUseCompatPadding Add padding on API 21 and later as well, so measurements match earlier versions. Boolean, such as true or false.
contentPadding Inner padding between the edges of the card and children of the CardView.
contentPaddingBottom Inner padding between the bottom edge of the card and children of the CardView.
contentPaddingLeft Inner padding between the left edge of the card and children of the CardView.
contentPaddingRight Inner padding between the right edge of the card and children of the CardView.
contentPaddingTop Inner padding between the top edge of the card and children of the CardView.

Remarks

CardView uses real elevation and dynamic shadows on Lollipop (API 21) and above. However, before Lollipop CardView falls back to a programmatic shadow implementation.

If trying to make an ImageView fit within the rounded corners of a CardView, you may notice it does not look correct pre-Lollipop (API 21). To fix this you should call setPreventCornerOverlap(false) on your CardView, or add app:cardPreventCornerOverlap="false" to your layout.

Before using the CardView you have to add the support library dependency in the build.gradle file:

dependencies{
    compile 'com.android.support:cardview-v7:25.2.0'
}

The current support-library version is listed here.

Official Documentation:

https://developer.android.com/reference/android/support/v7/widget/CardView.html

https://developer.android.com/training/material/lists-cards.html

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents