Closed hgg closed 6 years ago
Hi @Hugainz,
Thanks for the detailed description of your suggestion.
I'm afraid I don't see a possible way of having access to the "root view" of the whole section, as it doesn't exist. There isn't a single view for the whole section, if there was, it would defeat the concept of recycling views. Section is a concept created by the library to "group" the views displayed in the RecyclerView, but the views are still separated.
The current situation that you explained is the expected situation: you have a row span of 4 items, you have 5 items, so on the second row it displays 1 item and the other 3 items are missing.
I see few ways of trying to tackle the 'issue':
Let me know if you need more clarification.
Hi @luizgrp.
Thanks for your answer and clarifications. I now clearly understand why what I'm asking is not possible. I'll try to implement your suggestion, as creating the dummy icons and setting each icon background every time each item view is bound is really bad for performance.
Thanks again :+1:
1.1.3
8.0.0
Google
Nexus 5
Current Situation
Imagine you want to do something with each sections' view. For instance, changing it's background color. Since no XML is given by the user of the lib to serve as the section layout, the only way to do this would be programmatically. Currently, the only way to access the root view for each section is through something like this:
However, this is a terrible way to access the root view of the section, since for every ItemViewHolder created, some amount of unnecessary code will be run. Even using this method, the result is not quite as I expected, as I'm getting the following result instead of an even rectangle. I believe this is because I'm getting the rootView of the item and not of the section. Also tried chaining
getRootView()
calls, but I get the same view no matter how many times I chain it.I ended up creating dummy. invisible items that I use as placeholders to fill the empty space. However, this solution ended up polluting the code and is hardly elegant. So if you have any better idea on how to do this, I'd love to hear it.
Proposed Situation
My first proposal to solve this situation, which I don't know if it is possible, is to have a method on the Section class that returns the
rootView
of the section, allowing the user of library to simply call this on the Section's constructor and programmatically change whatever he'd like.Also a new builder method could be introduced to override the default view for the section, something like:
EDIT: Added some more considerations to the current situation section.