Android CardView Tutorial

Navjacinth Mathew
2 min readDec 27, 2016

In this tutorial we will Start off with CardView. It was introduced by Google from Android Lollipop (API 21). Card view is essentially a ViewGroup, which means it can contain other layouts. CardView widgets can have rounded corners and shadows using which we can create stunning Material Design user interface that is consistent across the android platform

Let’s start off implementing CardView. Start off a new empty project and follow the steps below:

Step 1 : Add the following dependency to your app level gradle file

Step 2 : In your activity_main.xml add the following code

Some of the CardView attributes used in the code above:

To get rounded corners for the CardView

card_view:cardCornerRadius="6dp"

To set background color for the CardView

card_view:cardBackgroundColor="#d1d1d1"

To add more shadow for the CardView

card_view:cardElevation="5dp"

To set padding for the CardView

card_view:contentPadding="10dp"

To add padding in API v21+ to have the same measurements with previous versions

card_view:cardUseCompatPadding="true"

To add padding to CardView on v20 and before to prevent intersections between the Card content and rounded corners

card_view:cardPreventCornerOverlap="true"

Step 3 : Now run your android application, you should see the output as shown below:

Output screenshot

Get the project code at GitHub

--

--