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

findLastCompletelyVisibleItemPosition 数据不正确 #7

Open
youlookwhat opened this issue Apr 23, 2020 · 2 comments
Open

findLastCompletelyVisibleItemPosition 数据不正确 #7

youlookwhat opened this issue Apr 23, 2020 · 2 comments

Comments

@youlookwhat
Copy link

使用StickyHeadersLinearLayoutManager后导致
lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastCompletelyVisibleItemPosition();不能正常获取到位置,去掉是好的。

@mwshubham
Copy link

+1

@IRMobydick
Copy link

to get rid of this issue:
in isViewValidAnchor(view, params) you should skip sticky headers when looking for a valid anchor.

private boolean isViewValidAnchor(View view, RecyclerView.LayoutParams params) {
    if (isStickyHeader(view)) {
        return false; // Skip sticky headers when looking for a valid anchor.
    }
    // Rest of the existing logic...
}

and then override findLastVisibleItemPosition() and update it with this:

@Override
public int findLastVisibleItemPosition() {
    int lastVisiblePosition = RecyclerView.NO_POSITION;
    for (int i = getChildCount() - 1; i >= 0; i--) {
        View child = getChildAt(i);
        int position = getPosition(child);

        if (!isStickyHeader(child)) {
            lastVisiblePosition = position;
            break;
        }
    }
    return lastVisiblePosition;
}

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