前言:
在做项目的时候,对于列表是每一个项目必不可少的东西,我们之前的实现是通过listview与graidView来实现列表数据展示,当RecycleView 的出现,给程序猿增加了一个更好的列表知识点
的探索,recycleView使用起来方便,样式种类多,不单一,使我们更好的追求,下面针对;RecycleView进行简单的讲解。
1.RecycleView的简介:
RecycleView是android5.0的新特性,他的出现慢慢顶替了ListView与GridView的市场,RecyclerView是用起来接偶性比较强,异常灵活,可以实现listView很难实现的效果。
2.RecycleView刷新的使用
我会把带有上拉刷新下拉加载的功能通过代码一起展示,后面会给项目的地址,大家不要着急,
效果图会截图展示给大家,
2.1. 创建项目,添加依赖(刷新的依赖等)
选中进行复制依赖:
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.android.support:design:26.1.0'
2.2 对xml布局进行编写:
选中进行复制xml:
<com.scwang.smartrefresh.layout.SmartRefreshLayout
android:id="@+id/refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
2.3. 在application设置上拉加载下拉刷新的样式初始:
首先新建一个Application
选中进行复制Application代码:
public class MyApp extends Application {
static {
//设置全局的header构造器
SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() {