Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

getScrollY StaggerGridView return 0 #194

Description

@amaydiam

I'm using Android-ParallaxHeaderViewPager and StaggeredGridView to create layout like pinterest. I getting problem when getScrollY, the result is sometimes return 0 when scroll at central position on the first row gird , Where first row grid with 2 column/items and different height each items.

imaging :
enter image description here

this the code :

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem,
                         int visibleItemCount, int totalItemCount, int pagePosition) {
        if (mViewPager.getCurrentItem() == pagePosition && visibleItemCount > 0) {
            int scrollY = getScrollY(view); // sometimes return 0, when scroll at central position on the first row .
        }
    }


 public int getScrollY(AbsListView view) {
        View c = view.getChildAt(0);
        if (c == null) {
            return 0;
        }

        int firstVisiblePosition = view.getFirstVisiblePosition();
        int top = c.getTop();

        int headerHeight = 0;
        if (firstVisiblePosition >= 1) {
            headerHeight = mHeaderHeight;
        }

        return -top + firstVisiblePosition * c.getHeight() + headerHeight;
    }

so how to fix it ?

Activity

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions