📅  最后修改于: 2023-12-03 14:52:12.337000             🧑  作者: Mango
在 Android 开发中,CardView 用于创建具有卡片式外观的视图容器。本文将向您介绍如何在 Android Studio 中添加 CardView 支持。
build.gradle
文件中添加以下依赖项:dependencies {
implementation 'com.google.android.material:material:1.3.0'
}
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="8dp"
app:cardElevation="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="这是一个 CardView 布局"
android:textSize="18sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="这是 CardView 中的文本视图"
android:textSize="16sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
注意,CardView 是一个容器,可以包含其他视图。
通过以上步骤,您已经成功地在 Android Studio 中添加了 CardView 支持。现在,您可以使用 CardView 来创建漂亮的卡片式视图容器,并将它们添加到您的应用程序中。