Created
October 30, 2020 13:47
-
-
Save nikartx/45f9d5e86f2181f01a0cefc5b37ed685 to your computer and use it in GitHub Desktop.
Scroll to position when RecyclerView place into NestedScrollView. Using LinearLayoutManagersmoothScrollTo and rvBlocks.scrollToPosition will not work when RecyclerView placed into NestedScrollView but this solution worked perfectly.
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
<androidx.core.widget.NestedScrollView | |
android:id="@+id/nswContent" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical"> | |
<androidx.recyclerview.widget.RecyclerView | |
android:id="@+id/rvBlocks" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:clipToPadding="false"/> | |
</LinearLayout> | |
</androidx.core.widget.NestedScrollView> | |
// Solution | |
fun navigateToBlock(position: Int) { | |
val scrollY = rvBlocks.getChildAt(position).y | |
nswContent.smoothScrollTo(0, scrollY.toInt()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HI i have posted question related scrollview can you please help me in this question https://stackoverflow.com/questions/70527432/how-to-scroll-vertically-for-specific-view-using-nested-scrollview-in-android