davideas / FlexibleAdapter

Fast and versatile Adapter for RecyclerView which regroups several features into one library to considerably improve the user experience :-)
Apache License 2.0
3.55k stars 553 forks source link

Divider at the end of a section #60

Closed jonathanyee closed 8 years ago

jonathanyee commented 8 years ago

Using RecyclerView.ItemDecoration creates a divider after every row and header. Is there a way to have the divider only show at the end of a section? Or should I make the divider a row?

Section header 1 section item 1 section item 2 divider Section header 2 section item 1 (no divider here)

jonathanyee commented 8 years ago

I tried making my 5dp divider into a row in the adapter and it broke the sticky header animation when it reaches a new header.

davideas commented 8 years ago

Hello @jonathanyee, you can create a custom ItemDecoration that displays the divider only when the next item is a header (avoiding the very first header of the list), and that should be the way to do it. We can try to work on it and if it is useful, we can include it in the library.

But you want an easier workaround, and if i understood well maybe you miss to set the same header also to the divider item (defined as ISectionable). If not, we need to investigate a bit more.

jonathanyee commented 8 years ago

How would I detect the next item is a header?

davideas commented 8 years ago

@jonathanyee, The idea is to combine some code of StickyHeaderHelper class and also the ItemDecoration in the project https://github.com/edubarr/header-decor.

Basically with RecyclerView.getChildAt(position) and RecyclerView.getChildAdapterPosition(child) and with my function isHeader(Item) I think it's possible to understand if a next item is a header. Then calculate the margins to create space between the items. I know it is difficult and it requires time. I will have a look in some weeks if I have time. For the moment it is better if you use the divider item...

davideas commented 8 years ago

@jonathanyee, I've modified the DividerItemDecoration to add a gap space (offset) only at the end of a section with items, now if you don't want the middle lines, the code in onDraw() method should be skipped to be executed. If you desire, would you customize that class for this library? lot of improvements can be done, for instance:

davideas commented 8 years ago

The modification I've added seems to work only with LinearLayout, with GridLayout it doesn't create the gap for the previous items that are on the same line of the last item... so, for Grid it must be fixed! Any idea?

jonathanyee commented 8 years ago

I'm sorry, can't think of any.

davideas commented 8 years ago

Available from v5.0.0-b6.