我在我的项目中使用了 swiperefreshlayout 和 recyclerview。当 recyclerview 不在第一项时,我希望禁用 swiperefreshlayout。我该怎么做? 我有一些代码,但没有用:
int topRowVerticalPosition = (myRecyclerView == null || myRecyclerView.getChildCount() == 0) ? 0 : myRecyclerView.getChildAt(0).getTop();
swipeRefreshLayout.setEnabled(layoutManager.findFirstCompletelyVisibleItemPosition() == 0 && topRowVerticalPosition >= 0);
最佳答案
您需要像这样向 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);
}
});
关于android - 当 RecyclerView 不在第一项时,如何禁用滑动刷新布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55575732/