rubensousa / GravitySnapHelper

A SnapHelper that snaps a RecyclerView to an edge.
Apache License 2.0
5k stars 615 forks source link

RecyclerView Auto Scrolling with GravitySnapHelper #40

Closed c0d3sling3r closed 6 years ago

c0d3sling3r commented 6 years ago

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

c0d3sling3r commented 6 years ago

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

rubensousa commented 6 years ago

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

rubensousa commented 6 years ago

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

SetareMaghari commented 6 years ago

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?

rubensousa commented 6 years ago

@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.

SetareMaghari commented 6 years ago

@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...

SetareMaghari commented 6 years ago

@rubensousa can you help me to solve it?

rubensousa commented 6 years ago

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.

rubensousa commented 6 years ago

Closing due to inactivity

osama-raddad commented 6 years ago

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

mehdijalalifar commented 6 years ago

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