As the name says, SmartRefreshLayout is a "smart" or "intelligent" pull-down refresh layout,because of its "smart", it does not just support all the Views , but also support multi-layered nested view structures. It extends from ViewGroup rather than FrameLayout or LinearLayout, this not only improves its performance, but also enables it to absorb the advantages of various refresh layouts in fashion now,Including Google official SwipeRefreshLayout、TwinklingRefreshLayout 、Ultra-Pull-To-Refresh. Also it integrates various cool Headers and Footers.
1.Add a gradle dependency.
//1.1.0 The API changes too much, old user upgrade should be cautious.
compile 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-alpha-3'
compile 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0-alpha-3'//Instead of using a special Header, you can skip this row.
compile 'com.android.support:appcompat-v7:25.3.1'// version 23 above (required)
2.Add SmartRefreshLayout in the layout xml.
<?xml version="1.0" encoding="utf-8"?>
<com.scwang.smartrefresh.layout.SmartRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
android:background="#fff" />
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
3.Coding in the Activity or Fragment.
RefreshLayout refreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout);
refreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh(RefreshLayout refreshlayout) {
refreshlayout.finishRefresh(2000);
}
});
refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
@Override
public void onLoadMore(RefreshLayout refreshlayout) {
refreshlayout.finishLoadMore(2000);
}
});
Copyright 2017 scwang90
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.
I hope you find this SmartRefreshLayout template useful.
Feel free to get in touch if you have any questions or suggestions.