Nestedscrollview Direct
| Do | Don't | |----|-------| | Use NestedScrollView with CoordinatorLayout for collapsing toolbars. | Put a RecyclerView with wrap_content inside it for long lists. | | Enable fillViewport to fill the screen when content is short. | Nest NestedScrollView inside another NestedScrollView . | | Keep inner lists small (< 10 items) or use multiple view types in a single RecyclerView . | Assume NestedScrollView is a drop-in performance upgrade – it has overhead. | | Test scroll fling behavior – physics can feel different. | Forget to handle keyboard visibility if the view contains EditText fields. | Final Take NestedScrollView is not a magic bullet, but it is an indispensable tool for modern, material-design-compliant Android apps. Use it when you need coordination , avoid it when you simply need containment . Respect the recycling system, and your scrolling will be buttery smooth.
Enter NestedScrollView . It is the sophisticated, collaborative sibling of the classic ScrollView , designed specifically to solve nested scrolling problems. NestedScrollView is a FrameLayout that extends ScrollView but implements NestedScrollingParent and NestedScrollingChild interfaces. In plain English: It can both receive scroll events from its children and coordinate scroll events with its parent. nestedscrollview
By attaching the appbar_scrolling_view_behavior to the NestedScrollView , the scroll events automatically trigger the AppBarLayout to expand or collapse. If you are using Jetpack Compose, the equivalent is Modifier.nestedScroll . The same principles apply: | Do | Don't | |----|-------| | Use
<TextView ... /> <androidx.recyclerview.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="wrap_content" android:nestedScrollingEnabled="true" /> <!-- Note this --> | Nest NestedScrollView inside another NestedScrollView
</LinearLayout> </androidx.core.widget.NestedScrollView> For the magic to work, the inner scrollable view (e.g., RecyclerView ) must have nested scrolling enabled. In modern AndroidX versions, this is true by default, but you can explicitly set it: