sticky-layoutmanager
sticky-layoutmanager copied to clipboard
findLastCompletelyVisibleItemPosition 数据不正确
使用StickyHeadersLinearLayoutManager
后导致
lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastCompletelyVisibleItemPosition();
不能正常获取到位置,去掉是好的。
+1
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;
}