RecycleView下拉刷新和加载另一种方式PtrClassicFrameLayout
PtrClassicFrameLayout和SwitchRefreshLayout是两种不同的刷新方式,根据项目实际要求去做
1.布局:
<in.srain.cube.views.ptr.PtrClassicFrameLayout android:id="@+id/mPtrClassicFrameLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:scrollbars="vertical" /> </in.srain.cube.views.ptr.PtrClassicFrameLayout>
2.在build.gradle(app)添加包:
//下拉刷新框架 compile 'in.srain.cube:ultra-ptr:1.0.11'
3.代码:
其中: app:ptr_resistance="1.7":设置下拉的阻尼系数,值越大感觉越难下拉 ptr_ratio_of_header_height_to_refresh:设置超过头部的多少时,释放可以执行刷新操作 ptr_duration_to_close:设置下拉回弹的时间 ptr_duration_to_close_header:设置刷新完成,头部回弹时间,注意和前一个进行区别 ptr_keep_header_when_refresh:设置刷新的时候是否保持头部 ptr_pull_to_fresh:设置下拉过程中执行刷新,我们一般设置为false 当然这几个参数的设置也可以通过代码去实现: // the following are default settings mPtrFrame.setResistance(1.7f); mPtrFrame.setRatioOfHeaderHeightToRefresh(1.2f); mPtrFrame.setDurationToClose(200); mPtrFrame.setDurationToCloseHeader(1000); // default is false mPtrFrame.setPullToRefresh(false); // default is true mPtrFrame.setKeepHeaderWhenRefresh(true);
实现刷新和加载更多效果:
/** * 上啦加载 */ mAdapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() { @Override public void onLoadMoreRequested() { new Handler().postDelayed(new Runnable() { @Override public void run() { getPresenter().getData(); mAdapter.setNewData(mList); mAdapter.loadMoreComplete(); mAdapter.notifyDataSetChanged(); } }, 2000); } }, mRecyclerView); //下拉刷新 mPtrClassicFrameLayoutFragment3.disableWhenHorizontalMove(true); mPtrClassicFrameLayoutFragment3.setPtrHandler(new PtrHandler() { @Override public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) { return PtrDefaultHandler.checkContentCanBePulledDown(frame, content, header); } @Override public void onRefreshBegin(PtrFrameLayout frame) { mList.clear(); getPresenter().getData(); mPtrClassicFrameLayoutFragment3.refreshComplete(); mAdapter.notifyDataSetChanged(); } });
其中 getPresenter().getData();这个是获取数据,根据实际项目数据获取而改变
相关推荐
XDgaozhan 2013-07-10
Geeny 2019-10-04
fuzhangandroid 2012-02-03
满城风絮 2011-12-03
Liuser 2016-01-09
Geeny 2019-06-30
lgzaaron 2017-04-25
bill0y 2017-03-18
familynt 2016-01-09
Tom天天 2015-05-09
GuangkuoDing 2015-04-22
Sunanang 2014-11-13
xuguolibeyondboy 2014-08-06
RungBy 2014-07-09
PrisonJoker 2013-07-10
huohu00 2013-02-01
lumitzs 2012-06-17