完美解決SwipeRefreshLayout與RecyclerView滑動衝突問題
阿新 • • 發佈:2019-01-22
直接上程式碼
另外網上還有重寫Recyclerview的方法,親測不管用,直接監聽Recyclerview的滑動即可。//解決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); } });