Skip to content

Commit

Permalink
增加 headerFooterAdapter#getFixedPosition 方法
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCheen committed Oct 18, 2022
1 parent 620a0ae commit 11d4044
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class HeaderFooterTestcase : BaseTestcaseFragment() {
toast("点击了 position = $position,是 Footer!")
return@doOnItemClick
}
val realPosition = if (position == 0) position else position - headerFooterAdapter.getHeaderCount()
val realPosition = headerFooterAdapter.getFixedPosition(position)
// val realPosition = if (position == 0) position else position - headerFooterAdapter.getHeaderCount()
toast("点击了 position = $position,model=${adapter.getItemData(realPosition)}")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ class HeaderFooterAdapter(var adapter: FlapAdapter) : RecyclerView.Adapter<Recyc
val preSpanSizeLookup = spanSizeLookup
spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
if (this@HeaderFooterAdapter.isHeaderOrFooter(position)){
if (this@HeaderFooterAdapter.isHeaderOrFooter(position)) {
return spanCount
}else {
} else {
return preSpanSizeLookup?.getSpanSize(position) ?: 1
}
}
Expand Down Expand Up @@ -237,6 +237,10 @@ class HeaderFooterAdapter(var adapter: FlapAdapter) : RecyclerView.Adapter<Recyc
}
return adapter.isStickyHeader(position - getHeaderCount())
}

fun getFixedPosition(position: Int): Int {
return if (position == 0) position else position - getHeaderCount()
}
}

const val ITEM_VIEW_TYPE_HEADER = 2123321000
Expand Down

0 comments on commit 11d4044

Please sign in to comment.