Sticky Headers doesn't shows in Expandable Sectionable Header, just view glitch
See original GitHub issueHi there. I’m facing with trouble. Trying to add sticky header to a multi expand list and wanna show top level header item as sticky but sticky header doesn’t shows just small glitch\twitch on scrolling back to this item. RecyclerView wrapped with FrameLayout. Idk whats wrong or its just a bug. Please help. The code listed below
Adapter init
FlexibleAdapter(emptyList(), this, true)
.setDisplayHeadersAtStartUp(true)
.setUnlinkAllItemsOnRemoveHeaders(true)
.setStickyHeaders(true)
Item
class ItemStructureUnit(val id: String,
@IntRange(from = 0, to = 9) val userExpandLevel: Int)
: AbstractExpandableItem<ItemStructureUnit.ViewHolder, ItemStructureUnit>(),
IHeader<ItemStructureUnit.ViewHolder>, ISectionable<ItemStructureUnit.ViewHolder, ItemStructureUnit> {
class ViewHolder(view: View?, adapter: FlexibleAdapter<out IFlexible<*>>?, isSticky: Boolean) : ExpandableViewHolder(view, adapter, isSticky)
private var header: ItemStructureUnit? = null
override fun bindViewHolder(adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>?, holder: ViewHolder, position: Int, payloads: MutableList<Any>?) {
%binding%
}
override fun getHeader() = header
override fun setHeader(header: ItemStructureUnit?) {
this.header = header
}
override fun getExpansionLevel() = userExpandLevel
override fun equals(other: Any?) = other is ItemStructureUnit && other.id == id
override fun createViewHolder(view: View?, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>?) = ViewHolder(view, adapter, userExpandLevel == 0)
override fun getLayoutRes() = R.layout.item_structure_unit
override fun hashCode(): Int {
var result = id.hashCode()
result = 31 * result + userExpandLevel
return result
}
}
Items creation:
val header = ItemStructureUnit(UUID.randomUUID().toString(), 0)
generateItemInDepth(header, depth = 9)
private fun generateItemInDepth(item: ItemStructureUnit, height: Int = 1, depth: Int = 9) {
if (depth == 1) {
return
}
for (i in 0..height) {
val subItem = ItemStructureUnit(UUID.randomUUID().toString(),
MAX_DEPTH - depth,/*expansion level*/
this).apply { header = item }
generateItemInDepth(subItem, depth = depth - 1)
item.addSubItem(subItem)
}
}
Logs:
D/StickyHeaderHelper: swapHeader newHeaderPosition=0
D/StickyHeaderHelper: clearHeader
D/StickyHeaderHelper: swapHeader newHeaderPosition=2
D/StickyHeaderHelper: clearHeader
V/FlexibleAdapter: onViewBound viewSize=16 ViewHolder ViewHolder{fce59c8 position=0 id=612776204, oldPos=-1, pLpos:-1 no parent}
D/StickyHeaderHelper: swapHeader newHeaderPosition=0
D/StickyHeaderHelper: clearHeader
...
etc same
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Issues with sticky header #320 - GitHub
Hi, I have some problems with the sticky header feature, used together with expand/collapse behavior Sometimes the sticky header view losses ...
Read more >Table headers position:sticky and border issue - Stack Overflow
I notice somehow I can see the content "behind" my header in the gap where the border "should" be. So I set the...
Read more >Sticky Headers for Table Views - Knack Community Forum
When I use this code my headers are no longer crossing over with data in the table but the header now moves up...
Read more >Sticky Headers: 5 Ways to Make Them Better
1. Maximize the Content-to-Chrome Ratio by Keeping It Small. Sticky headers inherently take up space on the screen that could be used for ......
Read more >Stop Using Fixed Headers and Start Using Sticky Ones
By using position: fixed on an element like the header, the element is ... Of course, the only downside is that it does...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@davideas thanks. all works.
@Null45, the
stickyHeader = true
is mandatory in case ofIHeader
, you can’t set false, because it’s a fixed workaround caused by the fact we can’t extend some methods and some fields are private in the base object. I repeat, if you have allIHeaders
you won’t have any sticky effect, the stitky routine will swap the header indefinitely, making the items normal.