Android CardView

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Introduction

A FrameLayout with a rounded corner background and shadow.

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

Due to expensive nature of rounded corner clipping, on platforms before Lollipop, CardView does not clip its children that intersect with rounded corners. Instead, it adds padding to avoid such intersection (See setPreventCornerOverlap(boolean) to change this behavior).

Parameters

ParameterDetails
cardBackgroundColorBackground color for CardView.
cardCornerRadiusCorner radius for CardView.
cardElevationElevation for CardView.
cardMaxElevationMaximum Elevation for CardView.
cardPreventCornerOverlapAdd padding to CardView on v20 and before to prevent intersections between the Card content and rounded corners.
cardUseCompatPaddingAdd padding in API v21+ as well to have the same measurements with previous versions. May be a boolean value, such as "true" or "false".
contentPaddingInner padding between the edges of the Card and children of the CardView.
contentPaddingBottomInner padding between the bottom edge of the Card and children of the CardView.
contentPaddingLeftInner padding between the left edge of the Card and children of the CardView.
contentPaddingRightElevation for CardView.
cardElevationInner padding between the right edge of the Card and children of the CardView.
contentPaddingTopInner 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'
}

A number of the latest version may be found here

Official Documentation:

https://developer.android.com/reference/android/support/v7/widget/CardView.html https://developer.android.com/training/material/lists-cards.html



Got any Android Question?