Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snap one by one #99

Open
akifsabeh opened this issue Jun 24, 2019 · 2 comments
Open

Snap one by one #99

akifsabeh opened this issue Jun 24, 2019 · 2 comments

Comments

@akifsabeh
Copy link

Is there an option to snap one item at a item no matter how fast the user flings?

@root-ansh
Copy link

i too request for this feature

@Tantu194
Copy link

Hi guys
@akifsabeh , @root-ansh
I tried this, and it works fine

recyclerView.onFlingListener = object : RecyclerView.OnFlingListener() {
                override fun onFling(velocityX: Int, velocityY: Int): Boolean {
                    if (abs(velocityX) > 3000) {
                        var cur = layoutManager.centerItemPosition
                        if (velocityX > 0) {
                            cur += 1
                        } else {
                            cur -= 1
                        }
                        if (cur >= list.size) {
                            cur = 0
                        } else if (cur < 0) {
                            cur = list.size - 1
                        }
                        recyclerView.smoothScrollToPosition(cur)
                        return true
                    }
                    return false
                }
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants