Mobile Development 12 min read

A New Technical Solution for Android Nested Scrolling: NestedScrollFrameLayout

Introducing NestedScrollFrameLayout, a FrameLayout subclass that implements NestedScrollingChild, enables any wrapped view to participate in Android nested scrolling—including touch and fling—without modifying the child, offering one‑click integration, smoother continuous scrolls, and dramatically lower development and maintenance costs.

Sohu Tech Products
Sohu Tech Products
Sohu Tech Products
A New Technical Solution for Android Nested Scrolling: NestedScrollFrameLayout

Background and Current Situation

In Android's event dispatch mechanism, once a parent view intercepts or consumes an event, child views cannot receive it. This limitation causes discontinuous nested scrolling because the child view cannot consume the portion of the scroll that the parent did not handle. The traditional mechanism forces the user to lift the finger to end the current event stream before the child can scroll.

Drawbacks of Existing Technical Solutions

To enable nested scrolling, a child view must implement one of the NestedScrollingChild interfaces and a parent view must implement a NestedScrollingParent interface. In complex business scenarios, many child views are ordinary Views or ViewGroups (e.g., FrameLayout, LinearLayout) that do not implement NestedScrollingChild. Making each of these ordinary views implement the interface incurs high development and maintenance costs, and third‑party modules may not be modifiable.

New Technical Solution

The proposed solution introduces a generic control NestedScrollFrameLayout that extends FrameLayout and implements NestedScrollingChild . By wrapping any child view with NestedScrollFrameLayout , the child gains nested‑scrolling capability without any code changes.

Principle Overview

NestedScrollFrameLayout handles both touch‑driven scrolling and fling‑induced inertia. When a touch event occurs, it checks whether the motion is a scroll. If so, it first dispatches the scroll distance to the cooperating parent via dispatchNestedPreScroll . Any unconsumed distance is then sent to the parent again via dispatchNestedScroll . The same process repeats until the finger is lifted, at which point stopNestedScroll notifies the parent that touch scrolling has ended.

Detailed Touch‑Scrolling Process

On onInterceptTouchEvent , the view receives the event stream (down, move…, up). During the down event it calls startNestedScroll , records the initial Y position ( mInitialTouchY ) and the last Y position ( mLastTouchY ).

It determines whether the motion is a scroll by comparing the absolute Y‑difference with mTouchSlop . If the difference exceeds the threshold, the view intercepts subsequent move and up events.

In onTouchEvent , the view calculates the scroll delta (current Y – mLastTouchY ) and dispatches it to the parent via dispatchNestedPreScroll . Unconsumed delta is then sent with dispatchNestedScroll . This loop continues until the finger lifts.

When the up event arrives, stopNestedScroll is called, ending the touch‑driven nested scroll.

Fling‑Induced Nested Scrolling

After the up event, startNestedScroll is invoked again to begin fling scrolling. VelocityTracker computes the Y‑velocity ( yVelocity ).

Using OverScroller , the view calculates fling offsets at each animation time step. Each offset is first sent to the parent via dispatchNestedPreScroll ; any remaining offset is forwarded with dispatchNestedScroll . This repeats until the fling finishes.

When the fling ends, stopNestedScroll notifies the parent that the inertia scrolling has completed.

Advantages of the Solution

One‑click integration: simply wrap the target view with NestedScrollFrameLayout .

No modification to child views is required, drastically reducing development and maintenance effort.

Supports both touch‑driven and fling‑driven nested scrolling, providing smooth, continuous interaction.

Applicable to various scenarios such as pull‑to‑refresh, CoordinatorLayout interactions, etc.

Terminology

View : Base class for all UI components in Android.

ViewGroup : A container that holds child Views.

FrameLayout : A simple ViewGroup that stacks its children.

Event Flow : Sequence of MotionEvent objects (down → move… → up).

Nested Scrolling : Interaction where both parent and child can scroll simultaneously.

NestedScrollingChild / NestedScrollingParent : Interfaces that enable coordinated scrolling between views.

mTouchSlop : Threshold distance to differentiate scroll from tap.

VelocityTracker : Utility to compute finger velocity.

OverScroller : Helper class to calculate fling offsets.

References

1. Android Nested Scrolling – https://blog.csdn.net/tmacfrank/article/details/120402886

2. Android NestedScrolling解决滑动冲突问题(2) – https://juejin.cn/post/6844903732539293704

3. Android Fling implementation – https://blog.csdn.net/qq_45383789/article/details/126007457

4. VelocityTracker usage – https://blog.csdn.net/c_he_n/article/details/82890061

5. Android View deep dive – https://it.cha138.com/ios/show-49309.html

6. NestedScroll advanced guide – https://juejin.cn/post/7191404521916989495

mobile developmentAndroidNested ScrollingCustom ViewFlingtouch events
Sohu Tech Products
Written by

Sohu Tech Products

A knowledge-sharing platform for Sohu's technology products. As a leading Chinese internet brand with media, video, search, and gaming services and over 700 million users, Sohu continuously drives tech innovation and practice. We’ll share practical insights and tech news here.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.