我在我的项目中使用swiperefreshlayout和recyclerview。我想在recyclerview不在第一项上时禁用swiperefreshlayout。我该怎么做? 我有一些代码,但是没有用:
int topRowVerticalPosition = (myRecyclerView == null || myRecyclerView.getChildCount() == 0) ? 0 : myRecyclerView.getChildAt(0).getTop();
swipeRefreshLayout.setEnabled(layoutManager.findFirstCompletelyVisibleItemPosition() == 0 && topRowVerticalPosition >= 0);
答案 0 :(得分:1)
您需要像这样向RecyclerView
添加一个OnScrollListener,并且可以使用RecyclerView
的第一个孩子的可见性来启用/禁用swipeRefreshLayout:
myRecyclerView.addOnScrollListener(new OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
View firstChild = recyclerView.getChildAt(0);
swipeRefreshLayout.setEnabled(firstChild.getVisibility() == View.VISIBLE);
}
});