SimpleRecyclerView icon indicating copy to clipboard operation
SimpleRecyclerView copied to clipboard

Header rows ignore ConstraintLayout/RelativeLayout directives

Open stevesamknows opened this issue 6 years ago • 6 comments

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) simplerecyclerview_header_rows_pull_left_not_expanding

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)
    }

stevesamknows avatar May 15 '18 07:05 stevesamknows

Probably duplicate of https://github.com/jaychang0917/SimpleRecyclerView/issues/32

stevesamknows avatar May 15 '18 09:05 stevesamknows

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

stevesamknows avatar May 15 '18 15:05 stevesamknows

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

stevesamknows avatar May 15 '18 15:05 stevesamknows

Version 2.0.3 should fix this issue.

jaychang0917 avatar May 16 '18 10:05 jaychang0917

Excellent -- works great, thank you for very fast turnaround

stevesamknows avatar May 16 '18 12:05 stevesamknows

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

stevesamknows avatar May 18 '18 17:05 stevesamknows