paint-brush
What is CardView in Android?by@akshay-rana-gujjar
1,183 reads
1,183 reads

What is CardView in Android?

by Akshay RanaJune 25th, 2020
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Cardview is a widget provided by the android to build a new look and efficient UI. Cardview was released with Android version 5.0 which is android lollipop. It is an amazing concept which makes your user experience better than old android UI. You can make your app look more professional see examples below. How to use cardview in your android project, first, we need to add cardview dependency in the gradle file. Add the dependency in your layout XML file and you can now use it like below.

Company Mentioned

Mention Thumbnail
featured image - What is CardView in Android?
Akshay Rana HackerNoon profile picture

Hello World, Today we are going to see what is cardview in android and what it’s advantages.

CardView is a widget provided by the android to build a new look and efficient UI. You can make your app look more professional see examples below. Cardview is an amazing concept which makes your user experience better than old android UI. Cardview was released with Android version 5.0 which is android lollipop.

According to Android’s Official Site, what is cardview:

CardView API as an easy way for you to show information inside cards that have a consistent look across the platform. These cards have a default elevation above their containing view group, so the system draws shadows below them. Cards provide an easy way to contain a group of views while providing a consistent style for the container.

What are the advantages of CardView?

Before the cardview, if we want to make something look like a card we mostly use framelayout but the problem with framelayout was that we need to write a lot of code to make simple changes but this was solved when cardview released and it has some more advantages as follows.

  • Cardview has elevation property for controlling shadow
  • Set the border or corner radius of the card
  • Changing background color is easy
  • Ripple effect on cardview looks super cool

These are some of the advantages but not the least.

How to add cardview in Android Project

To use cardview in your android project, first, we need to add cardview dependency in the gradle file.

add below line to add cardview dependency:

dependencies {
    ...
    
    implementation "androidx.cardview:cardview:1.0.0"

}

After pasting the above code hit the sync button at the top right of the screen corner, this will download the dependency on the project and you can use cardview.

After successfully syncing, open your layout XML file and you can now use cardview like below.

<androidx.cardview.widget.CardView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        
        >
  
  ....
  
  </androidx.cardview.widget.CardView>

Below are some cardview android examples:

And this is the end of this tutorial.

This article originally publish here: CardView in Android