解决嵌套的RecyclerView和SwipeRefreshLayout下滑冲突问题

 mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                //设置RecyclerView滑到顶部时,SwipeRefreshLayout才响应下拉刷新,否则响应RecyclerView下滑
                if (recyclerView == null) {
                    mSwipeRefreshLayout.setEnabled(true);
                }
                if (recyclerView != null) {
                    mSwipeRefreshLayout.setEnabled(recyclerView.getChildCount() == 0
                            || recyclerView.getChildAt(0).getTop() >= 0);
                    LogUtil.d("TAG", "top = " + recyclerView.getChildAt(0).getTop());
                }
            }
        });

你可能感兴趣的:(android)