NotBoringActionBar icon indicating copy to clipboard operation
NotBoringActionBar copied to clipboard

The value in getScrollY() method

Open machinezhou opened this issue 9 years ago • 1 comments

hi sir, I've read your blog and code , and it's great. But I got a little problem still bothering me.

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

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

int headerHeight = 0;
if (firstVisiblePosition >= 1) {
  headerHeight = mPlaceHolderView.getHeight();
}
return -top + firstVisiblePosition * c.getHeight() + headerHeight;

}

I tried to remove the "firstVisiblePosition * c.getHeight()" and it still work well. So I am still confused about the meaning of this statement.

machinezhou avatar Mar 24 '15 16:03 machinezhou

Hi Machinezhou, This function could be modified as follow :

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

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

        if (firstVisiblePosition >= 1) {
            return mFakeHeader.getHeight();
        }
        return -top;
}

cause it does not need (firstVisiblePosition * c.geHeight())

wangchauyan avatar Mar 29 '15 11:03 wangchauyan