CardView一般用于需要显示阴影效果的UI,此外CardView还提供了圆角的功能。(嘿嘿,这东西还能直接设置成圆形,可以简单的弄成圆形View)。CardView其实本身是使用FrameLayout 帧布局,所以它其实还是一个布局。
引用
CardView未在androidx全家桶套餐中,需要你自己添加
implementation ‘androidx.cardview:cardview:1.0.0’
一个简单的使用Demo
xml
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:app=“http://schemas.android.com/apk/res-auto”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
tools:context=".MainActivity">
<androidx.cardview.widget.CardView
android:id="@+id/card_view"
android:layout_width=“100dp”
android:layout_height=“100dp”
app:layout_constraintTop_toTopOf=“parent”