Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Chanven/CommonPullToRefresh
Android widget with pull to refresh for all the views,and support loadMore for ListView , RecyclerView, GridView and SwipeRefreshLayout.
https://github.com/Chanven/CommonPullToRefresh
Last synced: 3 months ago
JSON representation
Android widget with pull to refresh for all the views,and support loadMore for ListView , RecyclerView, GridView and SwipeRefreshLayout.
- Host: GitHub
- URL: https://github.com/Chanven/CommonPullToRefresh
- Owner: Chanven
- License: apache-2.0
- Created: 2015-09-23T06:45:05.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-29T09:22:53.000Z (over 7 years ago)
- Last Synced: 2024-06-16T01:35:05.128Z (5 months ago)
- Language: Java
- Homepage:
- Size: 8.67 MB
- Stars: 1,070
- Watchers: 56
- Forks: 303
- Open Issues: 60
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-github-android-ui - CommonPullToRefresh - 下拉刷新 (下拉刷新)
README
# CommonPullToRefresh
Android widget with pull to refresh for all the views,and support loadMore for ListView,RecyclerView,GridView and SwipeRefreshLayout.在[android-Ultra-Pull-To-Refresh](https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh)的基础上增加了加载更多的支持,感谢作者
* 下拉刷新支持大部分`view`:`ListView`、`ScrollView`、`WebView`等,甚至一个单独的`TextView`
* 加载更多目前支持`ListView`、`RecyclerView`、`GridView`、`SwipeRefreshLayout`
* 支持自定义header以及footer
* 增加SwipeRefreshLayout刷新方式,同样支持加载更多[Demo APK下载](https://raw.githubusercontent.com/Chanven/CommonPullToRefresh/master/raw/CommonPullToRefresh_Demo.apk)
#### ListView、RecyclerView截图
#### GridView截图
#### SwipeRefreshLayout截图# Usage
Gradle / Android Studio```
compile 'com.chanven.lib:cptr:1.1.0'
```
#### 下拉刷新配置有6个参数可配置:
* 阻尼系数
默认: `1.7f`,越大,感觉下拉时越吃力。
`mPtrFrame.setResistance(1.7f)`* 触发刷新时移动的位置比例
默认,`1.2f`,移动达到头部高度1.2倍时可触发刷新操作。
`mPtrFrame.setRatioOfHeaderHeightToRefresh(1.2f)`* 回弹延时
默认 `200ms`,回弹到刷新高度所用时间。
`mPtrFrame.setDurationToClose(200)`* 头部回弹时间
默认`1000ms`。
`mPtrFrame.setDurationToCloseHeader(1000)`* 刷新是保持头部
默认值 `true`。
`mPtrFrame.setKeepHeaderWhenRefresh(true)`* 下拉刷新 / 释放刷新
默认为释放刷新,即`false`。
`mPtrFrame.setPullToRefresh(false)`##### 上面是在`java`代码中配置,也可在`xml`文件中配置
```xml
```
#### 处理刷新通过`PtrHandler`,可以检查确定是否可以下来刷新以及在合适的时间刷新数据。
检查是否可以下拉刷新在`PtrDefaultHandler.checkContentCanBePulledDown`中有默认简单的实现,你可以根据实际情况完成这个逻辑。
```java
public interface PtrHandler {
/**
* 检查是否可以执行下来刷新,比如列表为空或者列表第一项在最上面时。
*
* {@link com.chanven.lib.cptr.PtrDefaultHandler#checkContentCanBePulledDown}
*/
public boolean checkCanDoRefresh(final PtrFrameLayout frame, final View content, final View header);/**
* 需要加载数据时触发
*
* @param frame
*/
public void onRefreshBegin(final PtrFrameLayout frame);
}
```
#### 加载更多配置
* 是否需要加载更多
默认`false`
`mPtrFrame.setLoadMoreEnable(true)`
* 是否自动加载
默认`true`
`mPtrFrame.setAutoLoadMoreEnable(true)`#### Header、Footer样式
* Header 实现接口`PtrUIHandler`,已有默认实现`PtrClassicDefaultHeader`,并通过`PtrFrameLayout.setHeaderView(View header)`设置
* Footer 实现接口`ILoadMoreViewFactory`,已有默认实现`DefaultLoadMoreViewFooter`,并通过`PtrFrameLayout.setFooterView(ILoadMoreViewFactory factory)`设置## 常见问题
* ViewPager滑动冲突: `disableWhenHorizontalMove()`
* 长按LongPressed, `setInterceptEventWhileWorking()`
* 如果要禁用下拉刷新,则更改`PtrHandler.checkCanDoRefresh`的返回实现即可具体栗子可参考Demo