两个(多个)RecyclerView联(滑)动实现

实现思路:设置滑动监听,滑动左边recycler,右侧recycler跟着移动相应距离即可(注意:条目高度要相等,如果添加分割线,注意分割线高度)

private void syncScroll(final RecyclerView rlvLeft, final RecyclerView rlvRight) {
    rlvLeft.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            if (recyclerView.getScrollState() != RecyclerView.SCROLL_STATE_IDLE) {
                // note: scrollBy() not trigger OnScrollListener
                // This is a known issue. It is caused by the fact that RecyclerView does not know how LayoutManager will handle the scroll or if it will handle it at all.
                rlvRight.scrollBy(dx, dy);
            }
        }
    });

    rlvRight.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            if (recyclerView.getScrollState() != RecyclerView.SCROLL_STATE_IDLE) {
                rlvLeft.scrollBy(dx, dy);
            }
        }
    });
}

你可能感兴趣的:(两个(多个)RecyclerView联(滑)动实现)