開發者能夠使用 PullToRefresh
對各類控件實現下拉刷新或者上拉加載以及能夠自定義刷新和加載部分的視圖。java
目前支持:ScrollView
,ListView
,WebView
,RecyclerView
。android
github地址:https://github.com/823546371/PullToRefreshgit
碼雲地址:http://git.oschina.net/jinwenfeng/PullToRefreshgithub
歡迎star or forkexpress
修復了滑動最小距離判斷apache
新增了空數據,加載中以及網絡錯誤的3種狀態頁面網絡
目前只支持 Android Studioapp
compile 'com.jwenfeng.pulltorefresh:library:1.1.0'
注意:內容控件 有且只能有一個,目前支持:ScrollView
,ListView
,WebView
,RecyclerView
。less
<?xml version="1.0" encoding="utf-8"?> <com.jwenfeng.library.pulltorefresh.PullToRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" 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>
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); } });
自定義下拉刷新視圖須要實現 HeadView
接口ide
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
上拉加載更多用法和下拉刷新相似,具體參考 LoadMoreView.java
能夠設置下拉刷新和上拉加載控件的高度和拉取的最大高度,默認爲60dp,最大拉取爲120dp,可自行設置。
<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_recycler_view" android:layout_width="match_parent" android:layout_height="match_parent" app:view_error="@layout/layout_error" app:view_empty="@layout/layout_empty" app:view_loading="@layout/layout_loading"> </com.jwenfeng.library.pulltorefresh.PullToRefreshLayout>
app:view_error 網絡錯誤頁面
app:view_empty 空數據頁面
app:view_loading 加載中頁面
該三個屬性能夠不填寫,默認樣式爲上圖所示,能夠自定義
pullToRefreshLayout.showView(ViewStatus.LOADING_STATUS);
設置須要顯示的視圖
// 獲取頁面 View error = pullToRefreshLayout.getView(ViewStatus.ERROR_STATUS);
獲取所須要的視圖view
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.