Results show

Page structure

plan

Inherit RecyclerView, rewrite dispatchNestedPreScroll&dispatchNestedPreFling, manage the consumption of eventsCopy the code

About the choice of the program

  • CoordinatorLayout&AppBarLayout&RecyclerView
This scheme has two problems: 1. The part above TAB is not flexible enough. AppBarLayout will limit the style of the app header. We will use a LinearLayout to draw each item separately and adjust the order of the product. Google's design is good, but for apps like e-commerce, the complexity of the head is far beyond imagination, and may encounter an effect that Is not supported by AppBarLayoutCopy the code
  • RecyclerView nested RecyclerView, plus event distribution
The event distribution mechanism has a natural flaw. Once the parent chooses to intercept the event, the child will no longer receive the event that the parent distributes. If down&move*n&up is consumed first by the parent and then by the child, event distribution is not possibleCopy the code
  • RecyclerView nested RecyclerView and nested scrollParent
RecyclerView$onTouchEvent Processes events based on nested scrolling: ---------------- scroll --------------- 1. Whether the parent consumes scroll event dispatchNestedPreScroll() 2. The parent consumes scrollByInternal() 3 DispatchNestedScroll () -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - fling -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - 4, whether the parent class consumption dispatchNestedPreFling fling events () 5, 4, not consumption, Parent dispatchNestedFling& mViewFlinger.fling()Copy the code

The plan was ready

RecyclerView (dispatchNestedPreScroll()&dispatchNestedPreFling())Copy the code

The source code

  • All do not put the source code to share are playing rogue
https://github.com/FangMessi/nested_scroll_demo
Copy the code

The source code

The last

  • Welcome to ask questions and discuss together
  • Code word is not easy, your praise is my motivation to continue to share