开发中常常用到列表下拉刷新功能,运用SmartRefreshLayout+RecyclerView可以简单实现此功能且界面友好
效果图:
首先添加依赖:
implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-alpha-20'
implementation 'com.android.support:recyclerview-v7:28.+'
ShowPbxxList.java
public class ShowPbxxList extends BaseActivity {
private RefreshLayout refreshLayout;
private RecyclerView recyclerView;
PbxxRecycleAdapter adapter;
List<ZxdBean> list1 = new ArrayList();
@Override
protected int setLayout() {
return R.layout.activity_pbxx;
}
@Override
protected boolean isTitle() {
return true;
}
@Override
protected void initView() {
refreshLayout = findViewById(R.id.refreshLayout);
recyclerView = findViewById(R.id.recyclerView);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
refreshLayout.setEnableLoadMore(false);//禁止上滑刷新
refreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
doRefresh();
}
});
}
@Override
protected void readInstanceState(Bundle savedInstanceState) {
}
@Override
protected void startView() {
isbacket(true);
setContentTitle("排班信息");
refreshLayout.autoRefresh();//启动时自动刷新
}
private void doRefresh() {
// 请求数据;
}
}
页面布局 activity_pbxx.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical">
<include layout="@layout/base_title" />
<com.scwang.smartrefresh.layout.SmartRefreshLayout
android:id="@+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.scwang.smartrefresh.layout.header.ClassicsHeader
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorGrey2"
android:overScrollMode="never" />
<com.scwang.smartrefresh.layout.footer.ClassicsFooter
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srlClassicsSpinnerStyle="Translate" />
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
</LinearLayout>
上拉下滑系统自带动画效果可以详看下面这个地址
http://www.cocoachina.com/articles/32556