I have a RecyclerView for displaying a list of items. There is this android CardView class given by android to show card layout. If I use a RelativeLayout and set its background to white it works the same way. Also in case of CardView I have to anyway add a childlayout to it which basically contains the all the views inside the card. So I wanted to know if their is any benefit of using a CardView (which actually increases the hierarchy of the views) rather than a normal Layout directly.
CardView is a new widget in Android that can be used to display any sort of data by providing a rounded corner layout along with a specific elevation. CardView is the view that can display views on top of each other. The main usage of CardView is that it helps to give a rich feel and look to the UI design.
Recycler view is more advanced version of list view and it works based on View holder design pattern. Using recycler view we can show grids and list of items. card view is extended by frame layout and it is used to show the items in card manner.
RelativeLayout : is a ViewGroup that displays child views in relative positions.
A RelativeLayout is a very powerful utility for designing a user interface because it can eliminate nested view groups and keep your layout hierarchy flat, which improves performance. If you find yourself using several nested LinearLayout groups, you may be able to replace them with a single RelativeLayout .
There are some advantages of cards over layouts, including:
All these and other features can be found in the card's design guideline.
In short:
CardView is google's way of styling RecyclerView. You can always use RelativeLayout or any other method prefered.
According to Google's design guidelines, definition of CardView is
Cards are a convenient means of displaying content composed of different elements. They’re also well-suited for showcasing elements whose size or supported actions vary, like photos with captions of variable length.
Using CardView, you get the default Google's look and feel throughout your app. You can customize cardview to your needs. That is why you need to have child layouts inside CardView. Plus Material Design is all about, elevation, colors and animation. CardView can have all these in a relatively easy manner.
It would be nice if you go through Google's design guide lines on CardView.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With