直接上代码
//解决swipelayout与Recyclerview的冲突
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
int topRowVerticalPosition =
(recyclerView == null || recyclerView.getChildCount() == 0) ? 0 : recyclerView.getChildAt(0).getTop();
swipeRefreshLayout.setEnabled(topRowVerticalPosition >= 0);
}
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
}
});
另外网上还有重写Recyclerview的方法,亲测不管用,直接监听Recyclerview的滑动即可。
来源:CSDN
作者:青穗CherishTang
链接:https://blog.csdn.net/fzkf9225/article/details/78931065