From ab7331660b1a4902c75060c00e23a53f60d0669b Mon Sep 17 00:00:00 2001 From: jinwenfeng <823546371@qq.com> Date: Wed, 14 Dec 2016 11:50:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 130 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4d07598..72e0468 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,131 @@ # PullToRefresh -初步完成 + +开发者可以使用 `PullToRefresh` 对各种控件实现下拉刷新或者上拉加载以及可以自定义刷新和加载部分的视图。 + +目前支持:`ScrollView `,`ListView`,`WebView`,`RecyclerView`。 + +## 基本用法 + +### 1、添加 Gradle 依赖 +> 目前只支持 Android Studio + +``` gradle +compile 'com.jwenfeng.pulltorefresh:library:1.0.1' +``` + +### 2、布局文件 +注意:内容控件 有且只能有一个,目前支持:`ScrollView `,`ListView`,`WebView`,`RecyclerView`。 + +``` xml + + + + + + + + + + +``` + +### 3、在Activity或者Fragment中使用 + +``` java +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); + } + }); +``` + +### 4、自定义视图 + +自定义下拉刷新视图需要实现 `HeadView` 接口 + +``` java +public interface HeadView { + + /** + * 开始下拉 + */ + void begin(); + + /** + * 回调的精度,单位为px + * + * @param progress 当前高度 + * @param all 总高度 + */ + void progress(float progress, float all); + + void finishing(float progress, float all); + /** + * 下拉完毕 + */ + void loading(); + + /** + * 看不见的状态 + */ + void normal(); + + /** + * 返回当前视图 + * */ + View getView(); + +} +``` +具体请参考Demo中 [HeadRefreshView](https://github.com/823546371/PullToRefresh/blob/master/library/src/main/java/com/jwenfeng/library/pulltorefresh/view/HeadRefreshView.java) + +上拉加载更多用法和下拉刷新类似,具体参考 [LoadMoreView.java](https://github.com/823546371/PullToRefresh/blob/master/library/src/main/java/com/jwenfeng/library/pulltorefresh/view/LoadMoreView.java) + +### 5、其他 + +可以设置下拉刷新和上拉加载控件的高度和拉取的最大高度,默认为60dp,最大拉取为120dp,可自行设置。 + +## License + +``` +Copyright 2016-2017 jinwenfeng + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +``` + + +