一个实现了下拉刷新/加载更多的android组件。现支持ListView、GridView、RecyclerView、ScrollView、NestedScrollView和ExpandableListView的下拉刷新/加载更多功能。
点击下载到设备
扫描二维码下载
Eclipse请copy源码或aar方式
通过Gradle抓取:
compile 'cn.finalteam.loadingviewfinal:loading-more-view:1.0.1'
compile 'cn.finalteam.loadingviewfinal:swipe-refresh-layout:1.0.1'
compile 'cn.finalteam.loadingviewfinal:ultra-pull-to-refresh:1.0.1'
compile 'cn.finalteam.loadingviewfinal:loading-more-style:1.0.1'
compile 'com.android.support:recyclerview-v7:23.2.1'//recyclerview随便哪个版本都可以,没有强制使用23.2.1
SwipeRefreshLayout和UPTR两个下拉刷新库可以二选一
注:使用UPTR+ListView/GridView/ScrollView...几乎类同
更多的UPTR功能和特性请点击这
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--使用PtrClassicFrameLayout套RecyclerViewFinal-->
<cn.finalteam.loadingviewfinal.PtrClassicFrameLayout
android:id="@+id/ptr_rv_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:ptr_duration_to_close="300"
app:ptr_duration_to_close_header="2000"
app:ptr_keep_header_when_refresh="true"
app:ptr_ratio_of_header_height_to_refresh="1.2"
app:ptr_resistance="1.7">
<cn.finalteam.loadingviewfinal.RecyclerViewFinal
android:id="@+id/rv_games"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="#00000000"
app:noLoadMoreHideView="false"<!--默认false-->
app:loadMoreMode="click|scroll"<!--默认scroll-->
app:loadMoreView="cn.finalteam.loadingviewfinal.DefaultLoadMoreView"<!--默认DefaultLoadMoreView,可在Java中配置-->
app:noLoadMoreHideView="false"<!--没有更多了是否隐藏footerview-->
/>
</cn.finalteam.loadingviewfinal.PtrClassicFrameLayout>
<include layout="@layout/layout_empty_view"/>
</FrameLayout>
mPtrLayout.autoRefresh();
mPtrLayout.setOnRefreshListener(new OnDefaultRefreshListener() {
@Override
public void onRefreshBegin(PtrFrameLayout frame) {
//发起下拉刷新请求
requestData(1);
}
});
mRecyclerViewFinal.setOnLoadMoreListener(new OnLoadMoreListener() {
@Override
public void loadMore() {
//发起加载更多请求
requestData(mPage);
}
});
mRecyclerViewFinal.setHasLoadMore(true/false);
mRecyclerViewFinal.showFailUI();
if (page == 1) { //page == 1表示下拉下拉
mPtrRvLayout.onRefreshComplete();//完成下拉刷新
} else {
mRecyclerViewFinal.onLoadMoreComplete();//完成加载更多
}
设置自定义样式请在setAdapter之前。
AVLoadMoreView avLoadMoreView = LoadMoreStyle.getAVLoadMoreViewFactory(context);
avLoadMoreView.setIndicatorColor(getResources().getColor(R.color.colorPrimary));
avLoadMoreView.setIndicatorId(AVLoadingIndicatorView.BallPulse);
mRecyclerViewFinal.setLoadMoreView(avLoadMoreView);
mRecyclerViewFinal.setNoLoadMoreHideView(true/false);//默认false不隐藏
注:onLoadMoreComplete()一定要在setHasLoadMore()和showFailUI()之后调用
具体实现代码请点击
<?xml version="1.0" encoding="utf-8"?>
<cn.finalteam.loadingviewfinal.SwipeRefreshLayoutFinal xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:refreshLoadingColor="@color/colorPrimary"><!--设置loading颜色-->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<include layout="@layout/layout_empty_view" />
</ScrollView>
<cn.finalteam.loadingviewfinal.RecyclerViewFinal
android:id="@+id/rv_games"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="#00000000"
android:divider="@null"
app:noLoadMoreHideView="false"<!--默认false-->
app:loadMoreMode="click|scroll"<!--默认scroll-->
app:loadMoreView="cn.finalteam.loadingviewfinal.DefaultLoadMoreView"<!--默认DefaultLoadMoreView,可在Java中配置-->
app:noLoadMoreHideView="false"<!--没有更多了是否隐藏footerview-->
</FrameLayout>
</cn.finalteam.loadingviewfinal.SwipeRefreshLayoutFinal>
与使用UPTR类同
这里具体不讲有兴趣请查看UPTR,当然后续会添加一个UPTR library样式库。
1、实现ILoadMoreView接口,并且实现其方法
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.