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

item 悬浮置顶加入下拉刷新 ,悬浮错位! #57

Closed
PYJVIP opened this issue Jul 8, 2022 · 2 comments
Closed

item 悬浮置顶加入下拉刷新 ,悬浮错位! #57

PYJVIP opened this issue Jul 8, 2022 · 2 comments

Comments

@PYJVIP
Copy link

PYJVIP commented Jul 8, 2022

加粗代码
新增以下代码可以解决错位问题:
①StickyGridLayoutManager下新增代码

private void cacheHeaderPositions() {
mHeaderPositions.clear();
List adapterData = mBaseAdapter.getData();
if (adapterData == null) {
if (mHeaderHandler != null) {
mHeaderHandler.setHeaderPositions(mHeaderPositions);
}
return;
}
for (int i = 0; i < adapterData.size(); i++) {
if (StickyHeaderHandler.TYPE_STICKY_VIEW == mBaseAdapter.getItemViewType(i)) {
### //--新增----当有下拉刷新的时候,position需要加上头部view count-------
int customTopItemViewCount = mBaseAdapter.getCustomTopItemViewCount();
mHeaderPositions.add(i+customTopItemViewCount);
//--新增----当有下拉刷新的时候,position需要加上头部view count-------
}

}
if (mHeaderHandler != null) {
mHeaderHandler.setHeaderPositions(mHeaderPositions);
}
}

②StickyHeaderHandler下新增代码

public void updateHeaderState(int firstVisiblePosition, Map<Integer, View> visibleHeaders, ViewHolderFactory viewFactory, boolean atTop) {
int headerPositionToShow = atTop ? INVALID_POSITION : getHeaderPositionToShow(firstVisiblePosition, visibleHeaders.get(firstVisiblePosition));
Log.i(TAG, "headerPositionToShow: " + headerPositionToShow);
View headerToCopy = visibleHeaders.get(headerPositionToShow);
if (headerPositionToShow != lastBoundPosition) {
if (headerPositionToShow == INVALID_POSITION || (checkMargins && headerAwayFromEdge(headerToCopy))) {
// 如果header刚好贴边,就无需加入
dirty = true;
safeDetachHeader();
lastBoundPosition = INVALID_POSITION;
} else {
// 否则就创建一个header视图
lastBoundPosition = headerPositionToShow;
//--新增----当有下拉刷新的时候,position需要加上头部view count-------
RecyclerView.ViewHolder viewHolder = viewFactory.getViewHolderForPosition(headerPositionToShow - getRecycleviewCustomTopItemViewCount());
attachHeader(viewHolder, headerPositionToShow - getRecycleviewCustomTopItemViewCount());
//--新增----当有下拉刷新的时候,position需要加上头部view count-------

}
} else if (checkMargins && headerAwayFromEdge(headerToCopy)) {
detachHeader(lastBoundPosition);
lastBoundPosition = INVALID_POSITION;
}
checkHeaderPositions(visibleHeaders);
mRecyclerView.post(new Runnable() {
@OverRide
public void run() {
checkElevation();
}
});
}

private int getRecycleviewCustomTopItemViewCount() {
int customTopItemViewCount = 0;
try {
BaseByRecyclerViewAdapter adapter = (BaseByRecyclerViewAdapter) mRecyclerView.getAdapter();
customTopItemViewCount = adapter.getCustomTopItemViewCount();
} catch (Exception e) {
}
return customTopItemViewCount;
}

@youlookwhat
Copy link
Owner

非常感谢提出!我这边看看。

@youlookwhat
Copy link
Owner

已经修复了哈,看最新的包就好了:

implementation 'com.github.youlookwhat:ByRecyclerView:1.3.2'

再次感谢提出!

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

2 participants