I have not tested this code and it's kind of psuedo code, also not sure if it's a good solution but wanna try to point you right direction. Maybe you find something useful.
Ignore the bad naming..
Create an interface that all the nested recycler view implements, that does the actual scrolling.
public interface ScrollListener {
void update(int scrollOffset);
}
implement in nested recycler views
public class NestedRecyclerViewFragment implements NestedScrollListener {
RecyclerView mRecyclerView;
@Override
public onCreate(Bundle savedInstance) {
mRecyclerView.addOnScrollListener {
public onScroll(int xOffset, int yOffset) {
if (getActivity() instanceof OnNestedRecyclerViewScrollListener) {
((OnNestedRecyclerViewScrollListener) getActivity()).onNestedScroll(xOffset);
}
}
}
}
....
@Override
protected void update(int scrollOffset) {
mRecyclerView.scrollTo(scrollOffset, 0);
}
....
}
Then you might have this other interface which the parent implements.
public interface OnNestedRecyclerViewScrollListener {
void onNestedScroll(int scrollOffset);
}
Which has the nested recycler views.
public class ParentFragment implements OnNestedRecyclerViewScrollListener {
Adapter nestedRecyclerViewAdapter;
....
@Override
protected void onNestedScroll(int scrollOffset) {
for (int i = 0; i < nestedRecyclerViewAdapter.getItemCount(); i++) {
RecyclerView recyclerView = nestedRecyclerViewAdapter.getItemAt(i);
if (recyclerView instanceof NestedScrollListener) {
((NestedScrollListener) recyclerView).update(scrollOffset);
}
}
}
....
}
Note: Might be bad to iterate the items in the adapter all the time but it might point you in right direction