1、添加依赖implementation‘com.android.support:cardview-v7:23.4.0’
2、设置CardView的圆角半径app:cardCornerRadius =""设就女蒿鸳置背景颜色app:cardBackgroundColor="设置paddingapp:contentPadding=" "app:contentPaddingTop=" "app:contentPaddingBottom=" "app:contentPaddingLeft=" "app:contentPaddingRight="注意啊:上面是CardView设置背景颜色和padding的方式,如果你直接通过android:padding=" " 和android:background=" "设置,是无效设置Z轴的高度app:cardMaxElevation=" "设置CardView的前景android:foreground =""设置内边距app:contentPadding ="
3、在项目中使用:<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:card_view="..."> <!-- A CardView that contains a TextView --> <android.support.v7.widget.CardView xmlns:card_view="..." android:id="@+id/card_view" android:layout_gravity="center" android:layout_width="200dp" android:layout_height="200dp" card_view:cardCornerRadius="4dp"> <TextView android:id="@+id/info_text" android:layout_width="match_parent" android:layout_height="match_parent" /> </android.support.v7.widget.CardView></LinearLayout>