之前使用这两种控件时,并未发现会有下拉刷新与上拉加载时会有顶部与底部布局覆盖遮挡问题
这次列表的每一项item的高度是根据获取的数据控制的,出现了布局遮挡和覆盖问题
在未下拉到顶部时就触发了SmartRefreshLayout的onRefresh()方法
同理未滑到底部完全显示完列表数据时就触发了onLoadMore()方法
通过对页面数据的观察,给出了一下解决方式:
refreshLayout.setScrollBoundaryDecider(new ScrollBoundaryDecider() {
@Override
public boolean canRefresh(View content) {
if (mRecycleList == null) return false;
LinearLayoutManager layoutManager = (LinearLayoutManager) mRecycleList.getLayoutManager();
int firstCompletelyVisibleItemPosition = layoutManager.findFirstCompletelyVisibleItemPosition();
if (firstCompletelyVisibleItemPosition == 0) {
View child = layoutManager.findViewByPosition(firstCompletelyVisibleItemPosition);
int deltaY = mRecycleList.getBottom() - mRecycleList.getPaddingBottom() -
child.getBottom();
// firstCompletelyVisibleItemPosition为0时说明列表滚动到了顶部, 不再滚动
if (deltaY > 0) {
mRecycleList.smoothScrollBy(0, -deltaY);
return true;
}
}
return false;
}
@Override
public boolean canLoadMore(View content) {
LinearLayoutManager layoutManager = (LinearLayoutManager) mRecycleList.getLayoutManager();
//屏幕中最后一个可见子项的position
int lastVisibleItemPosition = layoutManager.findLastCompletelyVisibleItemPosition();
//当前屏幕所看到的子项个数
int visibleItemCount = layoutManager.getChildCount();
//当前RecyclerView的所有子项个数
int totalItemCount = layoutManager.getItemCount();
//RecyclerView的滑动状态
int state = mRecycleList.getScrollState();
if (visibleItemCount > 0 && lastVisibleItemPosition == totalItemCount - 1 && state == mRecycleList.SCROLL_STATE_IDLE) {
return true;
} else {
return false;
}
}
});
以上处理方式可暂达到预期效果,处理刷新与加载时存在的顶部与底部的遮挡覆盖问题。
网友评论