我有一个ViewPager每页显示一个片段.此片段包含RecyclerView中的项目列表.项目列表始终具有相同的大小,并且项目的视图也具有相同的高度.当滚动其中一个RecyclerViews时,我希望其他RecyclerV
lvDetail& lvDetail2是您希望保持同步的RecyclerView.
final RecyclerView.OnScrollListener[] scrollListeners = new RecyclerView.OnScrollListener[2]; scrollListeners[0] = new RecyclerView.OnScrollListener( ) { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); lvDetail2.removeOnScrollListener(scrollListeners[1]); lvDetail2.scrollBy(dx, dy); lvDetail2.addOnScrollListener(scrollListeners[1]); } }; scrollListeners[1] = new RecyclerView.OnScrollListener( ) { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); lvDetail.removeOnScrollListener(scrollListeners[0]); lvDetail.scrollBy(dx, dy); lvDetail.addOnScrollListener(scrollListeners[0]); } }; lvDetail.addOnScrollListener(scrollListeners[0]); lvDetail2.addOnScrollListener(scrollListeners[1]);