一.在build.gradle(Module:app)中添加依赖:
1 implementation 'in.srain.cube:ultra-ptr:1.0.11'
二.xml文件(将要刷新的控件添加进此xml文件中)
1 <in.srain.cube.views.ptr.PtrClassicFrameLayout xmlns:cube_ptr="http://schemas.android.com/apk/res-auto" 2 xmlns:android="http://schemas.android.com/apk/res/android" 3 android:id="@+id/store_house_ptr_frame" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 7 cube_ptr:ptr_duration_to_close="300" 8 cube_ptr:ptr_duration_to_close_header="800" 9 cube_ptr:ptr_keep_header_when_refresh="true" 10 cube_ptr:ptr_pull_to_fresh="false" 11 cube_ptr:ptr_ratio_of_header_height_to_refresh="1.2" 12 cube_ptr:ptr_resistance="1.7"> 13 14 15 16 </in.srain.cube.views.ptr.PtrClassicFrameLayout>
三.MainAcitvity中添加:
1 mPtrClassicFrameLayout = (PtrClassicFrameLayout) findViewById(R.id.store_house_ptr_frame); 2 mPtrClassicFrameLayout.setPtrHandler(new PtrHandler() { 3 @Override 4 public void onRefreshBegin(PtrFrameLayout frame) { 5 frame.postDelayed(new Runnable() { 6 @Override 7 public void run() { 8 mPtrClassicFrameLayout.refreshComplete(); 9 mPtrClassicFrameLayout.setLastUpdateTimeKey("2017-2-10"); 10 } 11 }, 2000); 12 } 13 14 @Override 15 public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) { 16 return PtrDefaultHandler.checkContentCanBePulledDown(frame, content, header); 17 } 18 });