Here was my solution. The less the code the better...
lvDetail & lvDetail2 are the RecyclerViews you want to keep in sync.
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]);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…