How to Create Custom CardView in Android Studio

In this tutorial, we’re going to create a custom card view in android. Before that, if you do not know what CardView is then go through my previous tutorial on that, click here.

Also, you can go through how to implement recyclerView using CardView by clicking here, click here.

Why customized CardView?

CardView was announced by Google during its yearly I/O conference in 2014 as a part of Material Design components. The main purpose CardView serves in the Material Design universe is to provide a unified look to all of the card-based UIs making it easier for developers to create seamless interfaces.

In CardView, we can use as many elements as we want at different positions on the card. Which is not possible in any other widgets.

Customized CardView

  • First, add the CardView dependency in the app-level build.gradle file.
  • After that create the drawable background for the cards. For that, create New Drawable Resource File inside the drawable folder. res > drawable > New > Drawable Resource File.

bg1.xml

The output of the above code:

bg2.xml

The output of the above code:

bg3.xml

The output of the above code:

Also, import the required images into the drawable folder.

  • Now in the main XML file creates the card views. Here I used LinearLayout as the root widget, after that card view is used. Below codes that give you an idea of how to customize a card.
  • you can change it according to your requirements.

activity_main.xml

Output

for more android related tutorials please visit www.gbandroidblogs.com

HAPPY CODING!!

Hi everyone, myself Golap an Android app developer with UI/UX designer.