Nestedscrollview [upd] Jun 2026
Here is a typical example where you have a header image, some text, and then a list of items, all scrolling together smoothly.
| 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. | nestedscrollview
val nestedScrollView = findViewById (R.id.nested_scroll_view) val header = findViewById (R.id.header_layout) nestedScrollView.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener v, scrollX, scrollY, oldScrollX, oldScrollY -> // If the user has scrolled down at all, add a shadow (elevation) if (scrollY > 0) header.elevation = 8f // Adjust for desired shadow intensity else header.elevation = 0f // Flat when at the top ) Use code with caution. Copied to clipboard Key Benefits of this Feature Here is a typical example where you have
<!-- The Single Child Container --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> | | Enable fillViewport to fill the screen