Hackernoon logoWhat is CardView in Android? by@akshay-rana-gujjar

What is CardView in Android?

Author profile picture

@akshay-rana-gujjarAkshay Rana

Android and Web Developer

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

Tags

The Noonification banner

Subscribe to get your daily round-up of top tech stories!