rubensousa/GravitySnapHelper

RecyclerView Auto Scrolling with GravitySnapHelper

c0d3sling3r opened this issue · 11 comments

I use RTL horizontal recyclerview with LinearLayoutManager and set GravitySnapHelper(Gravity.END) to it. But after apply a little scroll to left, the recyclerview scrolls to left automatically without any user touches.
I attached a gif following to show the problem:
2017_12_08_14_58_08

I found out the problem. Because the recyclerview has a setReverseLayout(true) this happens.

Thanks for the report. I'll try to find a workaround.

Can you check version 1.5 please? It should be fixed now.

hi, i still have this problem, maybe im not using it in the correct way,
i instance the class as:
val SnapHelper = GravitySnapHelper(Gravity.END)
(its kotlin)

then i set layout-manager as:
layoutManager =
GridLayoutManager(context, 1, RecyclerView.HORIZONTAL, true)

is that correct for RTL horizontal scroll?

@SetareMaghari are you using 1.5? This issue was fixed on 1.5.

If you only have a span count of 1, you should use a LinearLayoutManager instead. But it should work anyway.

@rubensousa yes a use 1.5.
i changed it to linearlayout manager but i still have the problem...
also if i change it to ltr direction there is still the problem!
look at here:

its my code:
recycler.layoutManager =
LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
val SnapHelper = GravitySnapHelper(Gravity.START)
SnapHelper.attachToRecyclerView(recycler)

and the result:(it jumps to the first!)

ezgif-5-ea45f39327

also the same problem for RTL...

@rubensousa can you help me to solve it?

I can't reproduce this anymore on 1.5. Can you build a sample project and try to reproduce this? If so, please send it to me afterwards.

Closing due to inactivity

just use
val snapHelper = GravitySnapHelper(if (recyclerView.layoutDirection != Gravity.END) Gravity.START else Gravity.END)

if use :
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
in your activity , you need
1)add this code in recyclerView in adapter_snap.xml
android:layoutDirection="ltr"

2)snapAdapter.java
set reverseLayout:true
set Gravity:END

ezgif-3-0ddc694c1a