Why use a CardView instead of a RelativeLayout or LinearLayout?

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.

  • Captive portal on android device
  • How to distinguish if given Context object is an Activity or a Service Context?
  • Get position in ListView
  • Can I eavesdrop Android touch events?
  • AppCompat ToolBar popupTheme not used in the ShareAction MenuItem
  • getExternalFilesDir() returns null (not a permissions issue)
  • Related posts:

    How to use ActionBarActivity with Theme.Material
    Android Telegram App --> java.lang.UnsatisfiedLinkError: No implementation found for void
    ActionBar Dropdown Spinner item defaults to first item
    Prevent new activity instance after clicking on notification
    How to display GIF in react-native android app?
    gradle build Javadoc task fails with 'unknown tag: attr'
  • How to run an infinite loop in Android without freezing the UI?
  • Android Studio 2.0 Preview: ':app:transformClassesWithInstantRunForDebug' FAILED
  • how to get google project id and pushwoosh app id?
  • Timer in Background
  • PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT
  • How to add a horizontal 1px line above image view in a relative layout?
  • 2 Solutions collect form web for “Why use a CardView instead of a RelativeLayout or LinearLayout?”

    There are some advantages of cards over layouts, including:

    • Rounded corners, elevation, etc – visual improvements that come “out of the box” by just using cards
    • They support various lengths of the content. Actually layouts support that too, but in the context of list/grid views they are meant to have the same size, whereas cards can vary in length (for example when you show comments or descriptions)
    • Cards on the same hierarchy level can have different types of content/views, unlike layouts (list/grid items) which should have similar layouts when you show a collection

    All these and other features can be found in the card’s design guideline.

    In short:

    • I’d use cards when I want to display a collection of items which might have different lengths/heights depending on their content (like pictures with descriptions and comments) or a high number of supplemental actions.
    • I’d use Relative/Linear layouts when I want to display a simple collection of items, all/most of which have the same layout and a limited amount (max 1,2 lines) of text, an icon and an action,etc. elements that are the same for all items

    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.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.