简单介绍RecyclerView:
接触过Listview的就知道,相对RecyclerView来说,ListView存在很多不足之处,比如实现点击Item里某个文本或者图片效果,虽然也能实现,不够很复杂,而RecyclerView很好解决了这个问题。并且还能实现瀑布布局,横向布局等。而ListView却无法实现。并且谷歌更加推荐使用RecyclerView。
项目目录如下
第一步:引入官方的依赖库
我这引入的是
compile ‘com.android.support:recyclerview-v7:25.3.1’
注意要与你的项目
compile ‘com.android.support:appcompat-v7:25.3.1’
版本保持一致
下面是我的布局文件
activity_mian.xml
<?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.example.recyelerview.MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</android.support.constraint.ConstraintLayout>
以及item.xml