SimpleRecyclerView
SimpleRecyclerView copied to clipboard
Header rows ignore ConstraintLayout/RelativeLayout directives
Header items appear to be unable to use either percentage guidelines (if using ConstraintLayout) or align-to-right (if using RelativeLayout). This is unfortunate, because the data items themselves work perfectly with ConstraintLayout percentage guidelines, useful for aligning data into columns. In our case we want the subsection header row items to show labels for those columns, but due to this issue the header row layout directives are ignored, causing (severe) misalignment.
Even using ancient RelativeLayout is problematic as it also ignores directive to align to parent right edge -- the workaround for now is to use RelativeLayout and progressively lay items out left to right, but this puts us back in old-school dpi level territory, which was eliminated when ConstraintLayout percentages were introduced.
The image attached below demonstrates the same ConstraintLayout .xml (using percentage guidelines)
when used standalone vs. when added via SimpleRecylerView "SimpleSectionHeaderProvider"
(note that the data items themselves successfully use ConstraintLayout percentage
guidelines to arrange data in columns, but the header rows ignore those directives)
Not doing anything fancy, should be similar to the bundled demo app (in kotlin) e.g.
private fun addRecyclerHeaders(inflater: LayoutInflater, simpleRecyclerView: SimpleRecyclerView, historyListType: HistoryListType) {
val sh = object : SimpleSectionHeaderProvider<SKResultsUIList>() {
override fun getSectionHeaderView(skResultsUIList: SKResultsUIList, i: Int): View {
val view = inflater.inflate(R.layout.result_history_list_header_card_view, null, false)
...
return view
}
override fun isSameSection(currItem: SKResultsUIList, nextItem: SKResultsUIList): Boolean {
return currItem.simpleRVCategory === nextItem.simpleRVCategory
}
// Optional, whether the header is sticky, default false
override fun isSticky(): Boolean {
return true
}
}
simpleRecyclerView.setSectionHeader(sh)
}
Probably duplicate of https://github.com/jaychang0917/SimpleRecyclerView/issues/32
Tested another workaround: horizontal LinearLayout using weights to approximate percent widths (e.g. with weight of "1" and 8 elements, each element should be 12.5% of the width) But again (surprisingly with such a simple legacy layout) it all pulls severely left as above, simply has no concept of filling the parent width
Testing is as easy as modifying demo project to use a very simple RelativeLayout with two textViews; align one to parent right edge -- expect both to overlap at left edge at runtime
Version 2.0.3
should fix this issue.
Excellent -- works great, thank you for very fast turnaround
The width is now fixed, but height seems to have the same issue -- height will squash down to wrap content, and directives to expand (e.g. specifying a generous height in dp) will be ignored -- reopening