Card View – An Introduction

Hello friends it’s my first blog and i am going to show you guys how to use ‘CardView’ in your android application, to give your app an dynamic and user friendly look. First of all let’s discuss about what is CardView ;

    1. Android CardView in Android SDK which was introduced with the android material design through the support v7 library.  After reading this article you should feel comfortable to put anything over a CardView.
    2. Android CardView gives you a platform to put something over it like TextView, ImageView and any android widget.It also provides a more advanced and flexible way of implementing complex and custom listview with more functionality that is required nowadays for our apps.

Today we are going to create a CardView having two TextView and one ImageView.Which will look as example given below –

These are the following steps which will be followed by us :-

  1. Building to make package file compatible with CardView.
  2. Introducing CardView properties to .xml file i.e. layout file.
  3. Putting desired widgets in the CardView.

Open the Android Studio,start a new project named as CardView and choose “Empty Activity”.

Then we have to edit the ‘’ file to make the project compatible with CardView.Add

add the above lines under the dependencies.And, press “Sync now”.

Look at the image given below for the reference.

Moving towards second step :-

Add the following code in your .xml file where the layout properties are defined,

look at the image given below for reference

Now copy  the following code in your .xml or layout file  :-

After inserting the code in your .xml file, you will get an layout like the image given below :-

Don’t forget to put a source image in the drawable folder to let the image view on the ImageView present in the card view.

Here are some advise while working with CardView :-

  1. Never try to drag and drop widgets in the CardView, as,it will be thrown out of the CardView.
  2. Use only coding while moving widgets inside the CardView.

Even if you will drag CardView the elements within in it will be thrown out of the CardView.

So, always use coding while positioning Cards in your layout.

Thank you for visiting this tutorial. If you have any doubts or queries regarding this, you can comment below in our comment section. Please check our next part for remaining part of this tutorial.

In the next blog I will introduce you guys to the different elements of the CardView, which will give your Card layout an dynamic look.

Share this post

Leave a Reply

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