How to snap RecyclerView items so that every X items would be considered like a single unit to snap to?

后端 未结 3 1609
面向向阳花
面向向阳花 2020-11-30 01:27

Background

It\'s possible to snap a RecyclerView to its center using :

LinearSnapHelper().attachToRecyclerView(recyclerView)

Example

3条回答
  •  失恋的感觉
    2020-11-30 02:02

    I would do something like that

    1. Block scrolling inside RecyclerView (e.g How to disable RecyclerView scrolling?)

    2. Create Gesture Fling Detecor and attach it to RecyclerView

    3. Inside Gesture Detector detect fling events events
    4. On Fling event, detect side (left right)
    5. Scroll RecyclerView to position (first Visible item + your const * (left?-1:1))

    should work :)

提交回复
热议问题