sticky-layoutmanager icon indicating copy to clipboard operation
sticky-layoutmanager copied to clipboard

findLastCompletelyVisibleItemPosition 数据不正确

Open youlookwhat opened this issue 4 years ago • 2 comments

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

youlookwhat avatar Apr 23 '20 10:04 youlookwhat

+1

mwshubham avatar Sep 26 '23 14:09 mwshubham

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;
}

IRMobydick avatar Nov 12 '23 22:11 IRMobydick