一、添加依赖
dependencies { compile 'com.android.support:cardview-v7:26.1.0' }
点击右上角Sync Now
不会添加依赖或添加依赖出现错误,请见这篇文章
https://blog.csdn.net/weimeig/article/details/80244059
二、简单效果实现
1、 cardElevation:设置阴影的大小
2、 cardBackgroundColor:卡片布局的背景颜色
3、 cardCornerRadius:卡片布局的圆角的大小
4、 conentPadding:卡片布局和内容之间的距离
5、android:clickable="true"
6、android:foreground="?android:attr/selectableItemBackground"设置点击的水波纹效果
7、cardUseCompatPadding:是否设置内边距
扫描二维码关注公众号,回复:
887444 查看本文章
CardView简单效果
代码如下:
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.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="com.administrator.cardvieweaxmple.MainActivity"> <android.support.v7.widget.CardView android:layout_width="wrap_content" android:layout_height="wrap_content" app:cardBackgroundColor="@null" app:cardCornerRadius="10dp" app:cardElevation="20dp" app:cardUseCompatPadding="true"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher"/> </android.support.v7.widget.CardView> </android.support.constraint.ConstraintLayout>