HorStickyNavLayout: A Sticky Navigation Layout for RecyclerView with Interactive Prompt
This article introduces HorStickyNavLayout, a custom Android ViewGroup that enhances RecyclerView horizontal scrolling with a sticky footer prompting users to discover more content, detailing its architecture, nested scrolling handling, fling behavior, and animation logic to improve interaction without extra item views.
Background: With the rapid development of mobile internet, communication costs have dropped and information explosion requires efficient list scrolling components. RecyclerView is a widely used Android list component supporting vertical and horizontal scrolling.
Problem: In typical implementations, when RecyclerView reaches the far right, developers add an extra item view to prompt users to navigate to more content, which increases development effort, requires extra user interaction, and feels cumbersome.
New solution: HorStickyNavLayout is a generic component that eliminates the need for extra item views. It adds a FooterView outside the visible area of the RecyclerView and reveals it with a sticky, interactive prompt as the user continues to scroll, providing smooth, engaging navigation and handling fling inertia.
Principle: HorStickyNavLayout extends FrameLayout, inflates the RecyclerView as its child, and adds a FooterView positioned to the right. During measurement it records the RecyclerView height; during layout it places the FooterView at the far right. It implements NestedScrollingParent2 to coordinate nested scrolling with the RecyclerView, processing onStartNestedScroll, onNestedPreScroll, and onStopNestedScroll to adjust scroll offsets, reveal or hide the prompt based on a threshold MAX_WIDTH, and trigger appropriate animations.
Implementation details: The component distinguishes three cases—scroll distance below the threshold (show “continue sliding”), above the threshold (show “discover more” with a sticky effect), and fling‑induced inertia. It uses scrollBy to move the content, OffSetListener and ProgressAnimation for post‑scroll actions, and UnfoldAnimation for revealing the prompt when the distance is small.
FooterView: This view draws the prompt text on a canvas that translates horizontally according to scrollX, ensuring the text gradually appears from the right as the user scrolls.
Conclusion: HorStickyNavLayout provides a seamless, user‑friendly way to indicate additional content in a horizontally scrolling RecyclerView without extra item views, improving conversion rates and user experience.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.