下拉刷新上拉加载控件PullToRefresh
程序员文章站
2024-03-17 11:55:40
...
1、添加依赖
//下拉刷新
//https://github.com/823546371/PullToRefresh
implementation 'com.jwenfeng.pulltorefresh:library:1.2.7'
2、添加控件
<?xml version="1.0" encoding="utf-8"?>
<com.jwenfeng.library.pulltorefresh.PullToRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- 内容控件 有且只能有一个 -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
</ScrollView>
</com.jwenfeng.library.pulltorefresh.PullToRefreshLayout>
3、设置监听
查找控件后设置监听
@BindView(R.id.activity_main)
PullToRefreshLayout pullToRefreshLayout;
pullToRefreshLayout.setRefreshListener(new BaseRefreshListener() {
@Override
public void refresh() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// 结束刷新
pullToRefreshLayout.finishRefresh();
}
}, 2000);
}
@Override
public void loadMore() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// 结束加载更多
pullToRefreshLayout.finishLoadMore();
}
}, 2000);
}
});
结束刷新前处理刷新问题,结束加载前处理加载问题,我看到的资料是2016年,刚开始感觉太老了,刷新一搜一大堆,但是用起来还不错
上一篇: PHP在线常用颜色对照表
下一篇: 测试 Mark
推荐阅读