RecyclerView.addFooterView()后,若界面不刷新,则没有什么问题。
此处问题出现在Fragment页面切换后刷新,
每次刷新都会导致addfooterview尾部布局被优先加载出来。
观感上就不好。
起初在onViewCreated中加载Adapter初始化时,进行添加尾部布局
filterAdapter.addFooterView(footView)
但是会导致上述问题。每次更新界面都会重新加载,解决方法是
在Rv数据更新加载完后才进行加载尾部布局并做处理只加载一次,
以下是Rxjava的OnNext处理完数据并通知rv刷新
@Override
public void onNext(@io.reactivex.annotations.NonNull List<Date> date) {
Adapter.setList(date); //刷新数据
if (updateUIView){ //添加尾部布局,只添加一次
View footView = getLayoutInflater().inflate(R.layout.item_add_book, null);
footView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(requireActivity(), xxxx.class); //尾部跳转
startActivity(intent);
}
});
Adapter.addFooterView(footView);
updateUIView=false;
}
}
这样每次刷新,会在rv数据更新并展示之后才会展示尾部布局。