兩個(多個)RecyclerView聯(滑)動實現
阿新 • • 發佈:2019-02-17
實現思路:設定滑動監聽,滑動左邊recycler,右側recycler跟著移動相應距離即可(注意:條目高度要相等,如果新增分割線,注意分割線高度)
private void syncScroll(final RecyclerView rlvLeft, final RecyclerView rlvRight) { rlvLeft.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, intdx, 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); } } }); }