添加依赖
compile 'in.srain.cube:ptr-load-more:1.0.2'
在布局中
最上面加上
xmlns:cube_ptr="http://schemas.android.com/apk/res-auto"
然后:
<in.srain.cube.views.ptr.PtrClassicFrameLayout
android:id="@+id/ptr"
cube_ptr:ptr_duration_to_close="200"
cube_ptr:ptr_duration_to_close_header="1000"
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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</in.srain.cube.views.ptr.PtrClassicFrameLayout>
也可以在代码中设置:
// 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);
关于加载和刷新的:
ptr.setPtrHandler(new PtrDefaultHandler2() {
@Override
public void onLoadMoreBegin(PtrFrameLayout frame) {
list.add("111345345");
stringArrayAdapter.notifyDataSetChanged();
frame.refreshComplete();
}
@Override
public void onRefreshBegin(PtrFrameLayout frame) {
list.add("111");
stringArrayAdapter.notifyDataSetChanged();
frame.refreshComplete();
}
});
上拉加载,下拉刷新
最新推荐文章于 2022-10-15 18:46:37 发布