Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Divider at the end of a section #60

Closed
jonathanyee opened this issue Apr 4, 2016 · 8 comments
Closed

Divider at the end of a section #60

jonathanyee opened this issue Apr 4, 2016 · 8 comments

Comments

@jonathanyee
Copy link

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
Copy link
Author

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
Copy link
Owner

davideas commented Apr 5, 2016

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
Copy link
Author

How would I detect the next item is a header?

@davideas
Copy link
Owner

davideas commented Apr 6, 2016

@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
Copy link
Owner

@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:

  • support for horizontal
  • accepting a drawable object

@davideas
Copy link
Owner

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
Copy link
Author

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

@davideas
Copy link
Owner

davideas commented May 1, 2016

Available from v5.0.0-b6.

@davideas davideas closed this as completed May 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants