What is CardView and how to use it in Android?

Published by Shivam Pandey on

In Android, CardView is an element which is used to represent design information in a card manner with a drop shadow called elevation and corner radius. CardView was introduced in Material Design in API level 21 (Android 5.0 i.e Lollypop)

CardView Example :

 

Basic Cardview XML code in Android Studio :

<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content"> </android.support.v7.widget.CardView> 

Gradle dependencies to use CardView  :

The CardView widget is a part of separate library valid for API 7 level or higher. Add the following dependency in your Gradle build file to use CardView.

Add inside Gradle Scripts > build.gradle (Module: app) and inside dependencies

Attributes of CardView in Android :

1. card_view:cardBackgroundColor : This attribute is used to set the Background color for the CardView.

2. card view:cardCornerRadius : This attribute is used to set the corner radius for the CardView.

3. card_view:cardElevation : This attribute is used to set the elevation for the CardView. Elevation is used to show the shadow of the CardView.

4. card_view:contentPadding : This attribute is used to set the inner padding between the edges of the Card and children of the CardView. This attribute is used to set the equally padding between all the edges of the card and children of the CardView. We can also set the padding from bottom, top, left and right edges.

In case of any query you can comment that below or you can connect with the author on 

LINKEDIN  TWITTER

VISIT OUR WEBSITE BRIGHTERBEES FOR MORE INTERESTING STUFFS ABOUT ANDROID DEVELOPMENT.

IF YOU WANT TO KNOW ABOUT XML IN ANDROID click here.


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

STAY CONNECT WITH US