What is CardView in Android?

Written by akshay-rana-gujjar | Published 2020/06/25
Tech Story Tags: android | cardview | android-app-development | android-studio | android-development | androidapp | android-tutorial | android-cardview

TLDR 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.via the TL;DR App

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

Written by akshay-rana-gujjar | Android and Web Developer
Published by HackerNoon on 2020/06/25