We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
加粗代码 新增以下代码可以解决错位问题: ①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; }
The text was updated successfully, but these errors were encountered:
非常感谢提出!我这边看看。
Sorry, something went wrong.
fix 悬浮置顶加入下拉刷新 ,悬浮错位 #57
f9ce5b1
已经修复了哈,看最新的包就好了:
implementation 'com.github.youlookwhat:ByRecyclerView:1.3.2'
再次感谢提出!
No branches or pull requests
加粗代码
新增以下代码可以解决错位问题:
①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;
}
The text was updated successfully, but these errors were encountered: