Last active
August 1, 2022 20:01
-
-
Save chenzhang2006/5d693c161db0b82972d06bbfc7d34a5b to your computer and use it in GitHub Desktop.
RecyclerView State Sync Skeleton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Horizontle RecyclerView | |
val horizontalRecyclerView: RecyclerView = findViewById(R.id.horizontal_recycler_view) | |
val horizontalLayoutManager: LinearLayoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false) | |
horizontalRecyclerView.layoutManager = horizontalLayoutManager | |
// Vertical RecyclerView | |
val verticalRecyclerView: RecyclerView = findViewById(R.id.vertical_recycler_view) | |
val verticalLayoutManager: LinearLayoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false) | |
verticalRecyclerView.layoutManager = verticalLayoutManager | |
// ... When vertical list starts to render | |
// Transfer scroll position from horizontal list to vertical one | |
val horizontalScrollPosition = horizontalLayoutManager.findFirstVisibleItemPosition() | |
verticalRecyclerView.scrollToPosition(horizontalScrollPosition) | |
// ... When horizontal list starts to render | |
// Transfer scroll postion from vertical list to horizontal one | |
val verticalScrollPosition = verticalLayoutManager.findFirstVisibleItemPosition() | |
horizontalRecyclerView.scrollToPosition(verticalScrollPosition) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment