需求描述
我们在开发的时候经常需要用到下拉刷新的功能,但是经常UI会设计各种各样的下拉刷新功能,由于目前很多开源的下拉刷新的控件都进行了高度的自定义,我们在上面进行二次开发和修改比较困难,而且目前很多的下拉刷新控件,如果是在touchEvent里面进行操作修改那么基础类就很难改成其他的基础类,如果使用ViewGroup的onInterceptHoverEvent()方法来截取手势事件,截取后只能对整体进行操作,内容部分无法再次获得手势事件,体验不好。所以现在这个库就是用来解决这些问题的。
实现原理
我们把下拉刷新分为两个部分,头部和内容部分,内容部分下拉到顶部的时候即可进行下拉刷新的操作,内容部分可可根据下拉的进度进行自我调节,这里我们给出开始刷新,刷新完成,和刷新进度三个接口来进行回调,这样即可解决自定义的问题。另外我们外部用FrameLayout来进行包裹,但是不使用它的onInterceptHoverEvent()方法,而是使用它的dispatchTouchEvent()方法,通过一些状态来控制内容View的事件处理
库的优点
可实现高度自定义,更加的具有扩展性,体验更加的优化没有断了的感觉
Github地址
https://github.com/WinsonZhou/PullRefreshLayout
引用方式
Gradle
implementation 'com.github.winsonzhou:pullrefreshlayout:1.0.1'
Maven
<dependency>
<groupId>com.github.winsonzhou</groupId>
<artifactId>pullrefreshlayout</artifactId>
<version>1.0.1</version>
<type>pom</type>
</dependency>
示例代码
<com.winson.widget.pullrefreshlayout.PullRefreshLayout
android:id="@+id/pull_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.winson.widget.pullrefreshlayout.PullRefreshHeadLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@color/colorAccent"
android:orientation="vertical">
</com.winson.widget.pullrefreshlayout.PullRefreshHeadLayout>
<com.winson.widget.pullrefreshlayout.PullRefreshListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</com.winson.widget.pullrefreshlayout.PullRefreshLayout>
头部示例代码
@Override
public void onPullProgressUpdate(int progress) {
progressFlagTV.setText("onPullProgressUpdate : " + progress);
}
@Override
public void onRefresh() {
refreshFlagTV.setText("On Refresh!");
}
@Override
public void onRefreshComplete() {
refreshFlagTV.setText("Not on Refresh!");
}
@Override
public View getStick() {
return this;
}