Mobile Development 15 min read

Multi-Child View Nested Scrolling Solution in Baidu App

Baidu App replaced its original two‑view nested‑scrolling setup with a flexible, component‑based solution that leverages Android’s NestedScrolling API to coordinate any number of child views—via ILinkageScroll, LinkageScrollHandler and ChildLinkageEvent—handling pre‑scroll, fling, scrollbar aggregation, and a Xiaomi‑specific OverScroller fix, with code available open‑source.

Baidu App Technology
Baidu App Technology
Baidu App Technology
Multi-Child View Nested Scrolling Solution in Baidu App

This article describes Baidu App's implementation of multi-child view nested scrolling. Originally in 2017, they implemented 2-child view nested scrolling for Feed landing pages (WebView for article details + RecyclerView for native comments) using a "linkage container" to handle coordinated scrolling between WebView and RecyclerView. The original implementation had limitations: only supporting WebView and RecyclerView, and only 2 child views.

With the advancement of componentization, a more flexible solution was needed to support any type and any number of child views for nested scrolling. The implementation uses Google's NestedScrolling mechanism (introduced in Android 5.0), which uses a reverse event transmission mechanism for nested scrolling.

The core interface design includes ILinkageScroll (required for child views), LinkageScrollHandler (for scroll information queries), and ChildLinkageEvent (for scroll events like content reaching top/bottom). The scroll gesture handling in onNestedPreScroll() handles three cases based on comparing the container's scrollY with the child view's top edge. The fling gesture handling coordinates between the container and child views, transferring velocity when one reaches its scroll boundary.

For ScrollBar implementation, the container aggregates offset, extent, and range values from all child views. A notable compatibility fix for Xiaomi devices involves passing a non-zero value (1) to OverScroller.fling() instead of 0 to prevent mCurrVelocity from being NaN.

Open source references: https://github.com/baiduapp-tec/ELinkageScroll

AndroidCustom ViewFling GestureNestedScrollingScroll HandlingUI ComponentViewGroup
Baidu App Technology
Written by

Baidu App Technology

Official Baidu App Tech Account

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.