recyclerView的使用以及上拉加载 下拉刷新

本文介绍了Android中的RecyclerView,作为ListView和GridView的替代品,它具有更强的灵活性。详细展示了如何实现RecyclerView的上拉加载和下拉刷新功能,包括依赖添加、XML布局、设置样式、数据实体类、适配器编写以及在Activity中添加数据和功能实现。提供了完整的代码示例和运行效果截图,附带项目下载链接。
摘要由CSDN通过智能技术生成
前言:
在做项目的时候,对于列表是每一个项目必不可少的东西,我们之前的实现是通过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() {
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值