youlookwhat / ByRecyclerView

🔥 RecyclerView 下拉刷新、上拉松手/自动加载更多、item点击/长按、item局部刷新、头布局/尾布局/状态布局、万能分割线、Skeleton骨架图、极简adapter、嵌套滑动置顶
https://youlookwhat.github.io/ByRecyclerView
Apache License 2.0
798 stars 139 forks source link

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

Closed PYJVIP closed 2 years ago

PYJVIP commented 2 years ago

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

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

youlookwhat commented 2 years ago

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

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

再次感谢提出!