Skip to content

onPageScrolled returns zeros when scrolling between first and last item #4

Open

Description

@stevep99

LoopViewPager.onPageScrolled(...) has some logic whereby if the user scrolls left from the first item (i.e. looping across the first-last item boundary), then onPageScrolled returns zeros.

if (realPosition != mAdapter.getRealCount() - 1) {
    mOuterPageChangeListener.onPageScrolled(realPosition,
            positionOffset, positionOffsetPixels);
} else {
    if (positionOffset > .5) {
        mOuterPageChangeListener.onPageScrolled(0, 0, 0);
    } else {
        mOuterPageChangeListener.onPageScrolled(realPosition,
                0, 0);
    }
}

In my case I am scaling items depending on scroll position, but the problem would occur when anyone wants to use the onPageScrolled values. Basically whatever code logic the developer implements in his own onPageScrolled, this logic will fail when scroll transitions between first and last item in the list.

I have fixed this by having LoopViewPager.onPageScrolled always calling

mOuterPageChangeListener.onPageScrolled(realPosition,
                            positionOffset, positionOffsetPixels);

(i.e. removing the "if"-logic).

Is there are reason for the "if"-logic? Seems better to me to always return scroll values here.

Activity

  1. imbryk commented on Apr 8, 2014

    @imbryk
    Owner

    I see your point, and it's completely valid - I added the "if" as I was using with circle pager indicator, and without the zeros last circle was going outside.
    Probably it would be reasonable to allow user to set a flag if he wants to receive actual values between first and last element.
    I will have a second look at this in spare time (which I don't usually have ;) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions