Google has introduced CardView in Android L. Now your tools have one more widget to style your Android application. In this tutorial we will demonstrate the basic usage of Android CardView. It helps to create cards using a material design style. A material design is a new theme introduced in Android L. To run it on lower versions, there are available support libraries. They’re already included with Android studio.

We are going to implement cards using the CardView widget in Android. Make sure you add the compile dependency in the build.gradle file of Android Studio. They help to support material design in older versions of Android as well. Now you can use the CardView widget in our Android xml file.

Below you can find the screenshot of a card created using the CardView widget.

cards using android cardview

I am using Android studio. I’ll now create a basic Android CardView widget.

Basic App#1. Explanation of Android CardView widget.

  1. We are using the support library to enable CardView in older versions of Android.
  2. Like other view items, we need to set its ID.
  3. card_view:cardCornerRadius helps to define the radius for our cards.
  4. Add an Elevation or Shadow to the CardView by using card_view:cardElevation. 

I’ll now add one more CardView. I’m going to change the color, reduce the shadow (elevation) and add rounded corners to the CardView. Check below for the complete code of the activity_main.xml file. I have set the color to be #99CC00 (a shade of green) and increased the radius of corners to 40dp.

I haven’t customized my mainactivity yet. You can still see the code generated by Android studio below.

2 cardviews

Advanced tips on CardView

CardView extends FrameLayout. You can use any view hierarchy inside a CardView to build a layout for your application. You can then add the CardViews to your list. In a material design style, you can create  a listview using recyclerview and optimize it’s performance.

Basic App #2. How to add a CardView to a list using RecyclerView?

I have already implemented a list using the RecyclerView widget. If you are not familiar with  it then you must read that tutorial first.  Create a new project and add the compile dependency for both recyclerview and CardView.

listview using cardview and recyclerview

listview using CardView and recyclerview


Below you can see the source code of the activity_main.xml file. We have added the recyclerview widget. It will help to hold cards in a list.

Next you need to define the row of items for our listview. I will create a new xml file to hold one Android CardView widget. This CardView will have one textview. You can also add more views to it.


Now you need to implement a custom adapter for recyclerview. You can refer to adapter for recycler view for more details.

ViewHolder class (our custom class) gets the textview for us from the item.xml file. The onCreateViewHolder method helps to inflate the layout from the item.xml file. The onBindViewHolder helps to plug the data from an array to the textview.

Note: Let me know if you want to know anything else in the comment section. I would be happy to help.

Here’s the complete code for an Android list using CardView and recyclerview. Below you can find the code for

Now we have implemented a basic CardView in our Android application. Please comment in the section below and like our social pages to stay updated.