一、添加依赖
dependencies {
compile 'com.android.support:recyclerview-v7:26.1.0'
}
点击右上角Sync Now
不会添加依赖或添加依赖出现错误,请见这篇文章
https://blog.youkuaiyun.com/weimeig/article/details/80244059
二、列表效果实现
(一)、为RecyclerView添加填错数据的item
1、 cardElevation:设置阴影的大小
2、 cardBackgroundColor:卡片布局的背景颜色
3、 cardCornerRadius:卡片布局的圆角的大小
4、 conentPadding:卡片布局和内容之间的距离
5、android:clickable="true"
6、android:foreground="?android:attr/selectableItemBackground"设置点击的水波纹效果
7、cardUseCompatPadding:是否设置内边距
item_view.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:cardBackgroundColor="#eee"
app:cardCornerRadius="10dp"
app:contentPadding="10dp"
app:cardElevation="10dp"
app:cardUseCompatPadding="true">
<ImageView
android:id="@+id/img_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
android:layout_gravity="center"/>
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height