youlookwhat/ByRecyclerView

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

PYJVIP opened this issue · 2 comments

加粗代码
新增以下代码可以解决错位问题:
①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;
}

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

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

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

再次感谢提出!