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

Prevent snap on items which are bigger than the viewport #79

Open
pzxmsry opened this issue Mar 19, 2022 · 1 comment
Open

Prevent snap on items which are bigger than the viewport #79

pzxmsry opened this issue Mar 19, 2022 · 1 comment

Comments

@pzxmsry
Copy link

pzxmsry commented Mar 19, 2022

How to allow scrolling the item that is bigger than the screen size? Currently, it snaps to the start of the item when I try to scroll this big item. Is it possible to make the described behaviour?

@zhwanng
Copy link

zhwanng commented Jan 6, 2025

When the page is initialized, the width of the item is calculated, the RecyclerView is scrolled to the specified distance, and then bound to the viewPager, which does not trigger the problem of scrolling to the first position first.

private void navToSelectedPage(int index) {
if (index != -1) {
int x = (itemWidth + itemMargin * 2) * index;
binding.recyclerView.scrollBy(x, 0); // here
binding.pager.setCurrentItem(index, false);
}

    bindPager();
}

or you can use 'snapHelper.smoothScrollToPosition(position);'.

It boils down to the fact that the 'recyclerView.findViewHolderForAdapterPosition' in the 'scrollTo(position,false)' method returns null.

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

2 participants