DEV Community

Cover image for CardView Vs MaterialCardView
K M Rejowan Ahmmed
K M Rejowan Ahmmed

Posted on

8 1

CardView Vs MaterialCardView

As we're focusing more on design, Material Design is a hot topic here. Google's Material Library ( com.google.android.material ) created a huge impact in this area. Today I'm going to discuss one of the most used elements in the design, the CardView.

Google has introduced a new version of CardView called MaterialCardView . Both CardView and MaterialCardView could be used in the same cases and they look pretty similar. But there is still a vast difference in both design and functionality.

Let's start with some background data about these twos-

CardView

Previously, CardView was provided by Android Support Library (android.support.v7.widget.CardView). But with the latest migration to Andoridx, now it is provided by Androidx (androidx.cardview.widget.CardView) Library. CardView is created by extending the FrameLayout.

MaterialCardView

This is introduced with Google Material Library (com.google.android.material). It is provided by Material Components Library ( com.google.android.material.card.MaterialCardView). MaterialCardView is created by extending the CardView.

Differences

MaterialCardView has all the elements of CardView with its extra features. Here is a list containing the differences-

  • Stroke Color and Stroke Width can be added to MaterialCardView which wasn't possible using CardView.
  • MaterialCardView is Checkable. Check icon, color, and position can be set in MaterialCardView. Check conditions can be called also. This will be really useful as CardView has a huge usage in lists and grids.
  • Ripple Color can be set to MaterialCardView which is not available in CardView.

Code Example

CardView

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardBackgroundColor=""
app:cardCornerRadius=""
app:cardElevation=""
app:cardMaxElevation=""
app:cardPreventCornerOverlap=""
app:cardUseCompatPadding=""
app:contentPadding=""
app:contentPaddingBottom=""
app:contentPaddingLeft=""
app:contentPaddingRight=""
app:contentPaddingTop=""/>
view raw CardView.xml hosted with ❀ by GitHub

MaterialCardView
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:checkable=""
android:clickable=""
android:focusable=""
app:cardBackgroundColor=""
app:cardCornerRadius=""
app:cardElevation=""
app:cardMaxElevation=""
app:cardPreventCornerOverlap=""
app:cardUseCompatPadding=""
app:checkedIcon=""
app:checkedIconGravity=""
app:checkedIconSize=""
app:contentPadding=""
app:contentPaddingBottom=""
app:contentPaddingLeft=""
app:contentPaddingRight=""
app:contentPaddingTop=""
app:strokeColor=""
app:strokeWidth=""
app:shapeAppearance=""
app:cardForegroundColor=""
app:checkedIconMargin=""
app:checkedIconTint=""
app:rippleColor=""
app:shapeAppearanceOverlay=""
app:state_dragged="" />
view raw MaterialCardView.xml hosted with ❀ by GitHub

Shots

CardView
CardView Example

MaterialCardView
MaterialCardView Example

Details

Thanks for reading. Have a good day.

Find me on - Github, Facebook

More- CuteLibs Projects, CuteDialog

Sentry growth stunted Image

If you are wasting time trying to track down the cause of a crash, it’s time for a better solution. Get your crash rates to zero (or close to zero as possible) with less time and effort.

Try Sentry for more visibility into crashes, better workflow tools, and customizable alerts and reporting.

Switch Tools πŸ”

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay