com.google.android.material 和 android.support 的 CardView 有什么区别。v7.widget

What's the difference between the CardView from com.google.android.material and android.support.v7.widget

我想知道使用 Android Studio IDE 组件面板添加的小部件 android.support.v7.widget.CardView 和 [=] 上使用的 com.google.android.material.card.MaterialCardView 之间的区别39=] 设计文档。

它们是包含相同小部件的两个库吗?我应该使用哪一个以及如何做出这个决定?

我试图阅读更多 developers.android 文档,但是 developer.android 上的文档非常大,有很多版本,我还是有点困惑,找不到很好的解释所有这些版本,它的历史以及它是如何到达那里的。有人愿意让我了解这段历史吗?

Material 设计文档用法:

<com.google.android.material.card.MaterialCardView
    android:layout_width="match_parent"
   android:layout_height="wrap_content">
</com.google.android.material.card.MaterialCardView>

来源:https://material.io/develop/android/components/material-card-view/

使用AndroidStudio时添加的CardViewXML:

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</android.support.v7.widget.CardView>

我最近几天对 Android 图书馆的历史进行了研究,我得到了一个结论,我想分享一下:

  1. The component android.support.v7.widget.CardView is part of an old library and it's recommended to be replaced with com.google.android.material.card.MaterialCardView
  2. Android support library (android.support.*) is an old library that was replace by the new Android X Library in 2018 (which is part of Jetpack Library) and also by material components android

参考文献:

https://medium.com/@neerajmoudgil/upgrading-to-new-android-material-design-components-e62ddb03c3d2

https://developer.android.com/reference(它很大,但对于想要了解 Android 库的历史以及所有 Android 版本的初学者来说值得一看)

根据Material Design docs

MaterialCardView is a customizable component based on CardView from the Android Support Library. MaterialCardView provides all of the features of CardView, but adds attributes for customizing the stroke and uses an updated Material style by default.

有3个版本:

  • android.support.v7.widget.CardView:由旧支持库提供,已弃用。

  • androidx.cardview.widget.CardView 这是 androidx 版本,它替换了支持库。
    要使用它,您必须添加依赖项 implementation 'androidx.cardview:cardview:x.x.x'.

  • com.google.android.material.card.MaterialCardViewMaterial 组件库 提供。 要使用它,您必须添加依赖项实现 'com.google.android.material:material:1.1.0'.

MaterialCardView 扩展 androidx.cardview.widget.CardView 和 使用 MaterialShapeDrawable as background (it allows shaping and elevation overlays for Dark Themes).
引入了一些变化 MaterialCardView 也支持 checking and dragging.