Thường thì ứng dụng phải cho thấy dữ liệu trong các vùng chứa được định kiểu như nhau, chẳng hạn như các vùng chứa chứa thông tin về các mục trong danh sách. Hệ thống cung cấp API CardView để bạn cho thấy thông tin trong thẻ có giao diện nhất quán trên nền tảng. Ví dụ: các thẻ có độ cao mặc định lớn hơn nhóm thành phần hiển thị chứa chúng, vì vậy, hệ thống sẽ vẽ bóng đổ bên dưới. Thẻ cung cấp một cách để chứa một nhóm khung hiển thị trong khi vẫn cung cấp một kiểu nhất quán cho vùng chứa đó.
Hình 1. Giao diện người dùng của ứng dụng dựa trên thẻ.
Thêm phần phụ thuộc
Tiện ích CardView là một phần của AndroidX. Để sử dụng thành phần này trong dự án, hãy thêm phần phụ thuộc sau đây vào tệp build.gradle của mô-đun ứng dụng:
Để sử dụng CardView, hãy thêm thẻ này vào tệp bố cục. Sử dụng thẻ này làm nhóm thành phần hiển thị chứa cả các thành phần hiển thị khác. Trong ví dụ sau, CardView chứa một ImageView và một vài TextViews để hiển thị một số thông tin cho người dùng:
Đoạn mã trước đó tạo ra kết quả tương tự như sau, giả sử bạn sử dụng cùng một hình ảnh biểu trưng Android:
Hình 2. Ví dụ cơ bản về bố cục dựa trên CardView.
Thẻ trong ví dụ này được vẽ lên màn hình với độ cao mặc định, khiến hệ thống vẽ bóng đổ bên dưới. Bạn có thể cung cấp độ cao tuỳ chỉnh cho thẻ bằng thuộc tính card_view:cardElevation. Thẻ ở độ cao lớn hơn có bóng đổ rõ ràng hơn, còn thẻ ở độ cao thấp hơn có bóng đổ nhạt hơn. CardView sử dụng độ cao thực và bóng đổ động trên Android 5.0 (API cấp 21) trở lên.
Sử dụng các thuộc tính sau đây để tuỳ chỉnh giao diện của tiện ích CardView:
Để đặt bán kính góc trong bố cục, hãy sử dụng thuộc tính card_view:cardCornerRadius.
Để đặt bán kính góc trong mã, hãy sử dụng phương thức CardView.setRadius.
Để đặt màu nền của thẻ, hãy sử dụng thuộc tính card_view:cardBackgroundColor.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-08-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-08-27 UTC."],[],[],null,["Try the Compose way \nJetpack Compose is the recommended UI toolkit for Android. Learn how to work with layouts in Compose. \n[Card in Material 3 →](/develop/ui/compose/components/card) \n\n\u003cbr /\u003e\n\n| **Note:** For a better user experience, see [Material Design Cards](https://m3.material.io/components/cards/overview).\n\nApps often need to display data in similarly styled containers, such as\ncontainers that hold information about the items in a list. The system provides\nthe [`CardView`](/reference/androidx/cardview/widget/CardView) API for you to\nshow information in *cards* that have a consistent look across the platform. For\nexample, cards have a default elevation above their containing view group, so\nthe system draws shadows below them. Cards provide a way to contain a group of\nviews while providing a consistent style for the container.\n**Figure 1.** An app UI based on cards.\n\nAdd the dependencies\n\nThe `CardView` widget is part of [AndroidX](/jetpack/androidx). To use it in\nyour project, add the following dependency to your app module's `build.gradle`\nfile: \n\nGroovy \n\n```groovy\ndependencies {\n implementation \"androidx.cardview:cardview:1.0.0\"\n}\n```\n\nKotlin \n\n```kotlin\ndependencies {\n implementation(\"androidx.cardview:cardview:1.0.0\")\n}\n```\n\nCreate cards\n\nTo use a `CardView`, add it to your layout file. Use it as a view group to\ncontain other views. In the following example, the `CardView` contains an\n`ImageView` and a few `TextViews` to display some information to the user: \n\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003candroidx.constraintlayout.widget.ConstraintLayout\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n android:padding=\"16dp\"\n android:background=\"#E0F7FA\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\"\u003e\n\n \u003candroidx.cardview.widget.CardView\n android:layout_width=\"match_parent\"\n android:layout_height=\"wrap_content\"\n app:layout_constraintBottom_toBottomOf=\"parent\"\n app:layout_constraintEnd_toEndOf=\"parent\"\n app:layout_constraintStart_toStartOf=\"parent\"\n app:layout_constraintTop_toTopOf=\"parent\"\u003e\n\n \u003candroidx.constraintlayout.widget.ConstraintLayout\n android:padding=\"4dp\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\"\u003e\n\n \u003cImageView\n android:id=\"@+id/header_image\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"200dp\"\n android:src=\"@drawable/logo\"\n app:layout_constraintEnd_toEndOf=\"parent\"\n app:layout_constraintStart_toStartOf=\"parent\"\n app:layout_constraintTop_toTopOf=\"parent\" /\u003e\n\n \u003cTextView\n android:id=\"@+id/title\"\n style=\"@style/TextAppearance.MaterialComponents.Headline3\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"wrap_content\"\n android:layout_marginTop=\"4dp\"\n android:text=\"I'm a title\"\n app:layout_constraintEnd_toEndOf=\"parent\"\n app:layout_constraintStart_toStartOf=\"parent\"\n app:layout_constraintTop_toBottomOf=\"@id/header_image\" /\u003e\n\n \u003cTextView\n android:id=\"@+id/subhead\"\n style=\"@style/TextAppearance.MaterialComponents.Subtitle2\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"wrap_content\"\n android:layout_marginTop=\"4dp\"\n android:text=\"I'm a subhead\"\n app:layout_constraintEnd_toEndOf=\"parent\"\n app:layout_constraintStart_toStartOf=\"parent\"\n app:layout_constraintTop_toBottomOf=\"@id/title\" /\u003e\n\n \u003cTextView\n android:id=\"@+id/body\"\n style=\"@style/TextAppearance.MaterialComponents.Body1\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"wrap_content\"\n android:layout_marginTop=\"4dp\"\n android:text=\"I'm a supporting text. Very Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\"\n app:layout_constraintEnd_toEndOf=\"parent\"\n app:layout_constraintStart_toStartOf=\"parent\"\n app:layout_constraintTop_toBottomOf=\"@id/subhead\" /\u003e\n \u003c/androidx.constraintlayout.widget.ConstraintLayout\u003e\n \u003c/androidx.cardview.widget.CardView\u003e\n \u003c/androidx.constraintlayout.widget.ConstraintLayout\u003e\n\nThe previous code snippet produces something similar to the following, assuming\nyou use the same Android logo image:\n**Figure 2.** A basic example of CardView-based layout.\n\nThe card in this example is drawn to the screen with a default elevation, which\ncauses the system to draw a shadow under it. You can provide a custom elevation\nfor a card with the `card_view:cardElevation` attribute. A card at a higher\nelevation has a more pronounced shadow, and a card at a lower elevation has a\nlighter shadow. `CardView` uses real elevation and dynamic shadows on Android\n5.0 (API level 21) and higher.\n\nUse these properties to customize the appearance of the `CardView` widget:\n\n- To set the corner radius in your layouts, use the `card_view:cardCornerRadius` attribute.\n- To set the corner radius in your code, use the `CardView.setRadius` method.\n- To set the background color of a card, use the `card_view:cardBackgroundColor` attribute."]]