详细资料地址: https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh
要先添加依赖包:
布局文件:
<in.srain.cube.views.ptr.PtrFrameLayout xmlns:cube_ptr="http://schemas.android.com/apk/res-auto" android:id="@+id/store_house_ptr_frame" android:layout_width="match_parent" android:layout_height="match_parent" cube_ptr:ptr_duration_to_close="300" cube_ptr:ptr_duration_to_close_header="2000" cube_ptr:ptr_keep_header_when_refresh="true" cube_ptr:ptr_pull_to_fresh="false" cube_ptr:ptr_ratio_of_header_height_to_refresh="1.2" cube_ptr:ptr_resistance="1.7"> <LinearLayout android:id="@+id/store_house_ptr_image_content" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/colorAccent" android:clickable="true" android:padding="10dp"> <android.support.v7.widget.RecyclerView android:id="@+id/rv_data" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> </in.srain.cube.views.ptr.PtrFrameLayout>
代码:
mPtrFrame = (PtrFrameLayout) findViewById(R.id.store_house_ptr_frame); 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); rvData = (RecyclerView) findViewById(R.id.rv_data); rvData.setAdapter(new DataAdapater()); View view = LayoutInflater.from(this).inflate(R.layout.item,null); mPtrFrame.setHeaderView(view); //这里设置你想要的布局 //刷新的方法 mPtrFrame.setPtrHandler(new PtrHandler() { @Override public void onRefreshBegin(PtrFrameLayout frame) { frame.postDelayed(new Runnable() { @Override public void run() { mPtrFrame.refreshComplete(); } }, 1800); } @Override public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) { return PtrDefaultHandler.checkContentCanBePulledDown(frame, content, header); } });