Android-Ultra-Pull-To-Refresh

    xiaoxiao2021-03-25  109

    持续更新:

    一.最简单用法

    1.gradle中添加:

    // Ultra-Pull-To-Refresh框架的依赖 GitHub

    compile 'in.srain.cube:ptr-load-more:1.0.6' 2.XML中添加:

    <in.srain.cube.views.ptr.PtrFrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ptr="http://schemas.android.com/apk/res-auto" android:id="@+id/ptr" android:layout_width="match_parent" android:layout_height="match_parent" ptr:ptr_duration_to_close_header="1000" ptr:ptr_keep_header_when_refresh="true" ptr:ptr_pull_to_fresh="false" ptr:ptr_ratio_of_header_height_to_refresh="1.2" ptr:ptr_resistance="1.7"> <各种View android:id="@+id/view_id" android:layout_width="match_parent" android:layout_height="match_parent" /> </in.srain.cube.views.ptr.PtrFrameLayout>

    3. Activity中添加代码:

    private PtrFrameLayout mPtrFrame;

    mPtrFrame = (PtrFrameLayout) findViewById(R.id.ptr);

    final PtrClassicDefaultHeader header = new PtrClassicDefaultHeader(this); header.setPadding(0, PtrLocalDisplay.dp2px(15), 0, 0); mPtrFrame.setHeaderView(header); // mPtrFrame.setPinContent(true);//刷新时,保持内容不动,仅头部下移,默认,false mPtrFrame.addPtrUIHandler(header); mPtrFrame.setPtrHandler(new PtrHandler() { //需要加载数据时触发 @Override public void onRefreshBegin(PtrFrameLayout frame) { System.out.println("MainActivity.onRefreshBegin"); mPtrFrame.postDelayed(new Runnable() { @Override public void run() { mPtrFrame.refreshComplete(); //自动刷新 } }, 1800); } /** * 检查是否可以执行下来刷新,比如列表为空或者列表第一项在最上面时。 */ @Override public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) { System.out.println("MainActivity.checkCanDoRefresh"); // 默认实现,根据实际情况做改动 return PtrDefaultHandler.checkContentCanBePulledDown(frame, content, header); // return true; } });

    二.源码分析:

    三.自定义扩展:

    转载请注明原文地址: https://ju.6miu.com/read-19356.html

    最新回复(0)