1

I am using FocusLayoutManager for RecyclerView. Everything is fine but I need to swipe only one item at a time. I have also tried LinearSnapHelper and others too, i.e. SnapHelperOneByOne but didn't helped. Also tried to modify the focus layout manager class itself but all in vain. Any help would be appreciated.

  1. Link for FocusLayoutManager

  2. Link for SnapHelperOneByOne

  3. Link for FocusLayoutManagerLibrary

Note: I have tried to attach the SnapHelper to RecyclerView after layout manager is assigned.

 val focusLayoutManager = FocusLayoutManager.Builder()
        .focusOrientation(FocusLayoutManager.FOCUS_TOP)
        .isAutoSelect(true)
        .maxLayerCount(1)
        .setOnFocusChangeListener { focusdPosition, lastFocusdPosition -> }
        .build()
myRecycler.layoutManager = focusLayoutManager

Using Snap Helper doesn't help also and makes the scrolling lagging (jerks)

val mySnapHelper = SnapHelperOneByOne()
mySnapHelper.attachToRecyclerView(myRecycler)
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • What behavior are you looking to achieve? It sounds like a bad user experience to only be able to scroll one item at a time. are you sure you don't want a ViewPager instead? – Gavin Wright Sep 01 '20 at 11:38
  • I have a full screen card to scroll only one item at a time, And yes, I don't want to use ViewPager as the transition/animation effect I want is been provided by focusLayoutManager class I have shared above. – Moiz Hassan Khan Sep 01 '20 at 11:41

1 Answers1

5

Got stuck with the same issue. Set the focus change listener code like below. (Found one work around for Java)

.setOnFocusChangeListener((focusdPosition, lastFocusedPosition) -> {
  if (focusdPosition == lastFocusedPosition - 1 || focusdPosition == lastFocusedPosition + 1) {
      myRecycler.stopScroll();
  }
})

This code will stop the scroll for the RecyclerView, if the current focused item is after or before the previous focused item then it will stop the scroll.

Remove the SnapHelper because it creates a scroll animation lag with FocusLayoutManager.

pradyot1996
  • 1,044
  • 8
  • 15
  • Thank you for your answer, I found a workaround by changing the on-fling listener of the RecyclerView and that helped in changing the scrolling behaviour to the problem. – Moiz Hassan Khan Jan 12 '21 at 12:06