-
-
Notifications
You must be signed in to change notification settings - Fork 45
Usage
Giorgio Antonioli edited this page May 18, 2020
·
7 revisions
The default divider is configured using the values of the theme attributes and it can be attached to a RecyclerView
in Kotlin with:
// Using LinearLayoutManager or GridLayoutManager.
recyclerView.addDivider()
// Using StaggeredGridLayoutManager.
recyclerView.addStaggeredDivider()
And in Java with:
// Using LinearLayoutManager or GridLayoutManager.
DividerDecoration.attachTo(recyclerView)
// Using StaggeredGridLayoutManager.
StaggeredDividerDecoration.attachTo(recyclerView)
By default, all the dividers can be customized with these theme attributes:
-
android:listDivider
orrecyclerViewDividerDrawable
→ the divider'sDrawable
or color -
recyclerViewDividerSize
→ the divider's size (otherwise it would be inherited by theDrawable
) -
recyclerViewDividerInsetStart
→ the start inset of the divider'sDrawable
(otherwise 0) -
recyclerViewDividerInsetEnd
→ the end inset of the divider'sDrawable
(otherwise 0) -
recyclerViewDividerTint
→ the tint of the divider'sDrawable
(otherwise theDrawable
won't be tinted) -
recyclerViewDividerAsSpace
→ true if the divider will behave as a simple space, without drawing anything (by default it's false)
Each divider can be customized programmatically using the classes DividerBuilder
and StaggeredDividerBuilder
.
The properties of a divider specified programmatically win over the theme attributes.
Using LinearLayoutManager
and GridLayoutManager
, the correct builder class is DividerBuilder
which can be instantiated in Kotlin with:
context.dividerBuilder().addTo(recyclerView)
And in Java with:
DividerDecoration.builder(context).addTo(recyclerView)
Using StaggeredGridLayoutManager
, the correct builder class is StaggeredDividerBuilder
which can be instantiated in Kotlin with:
context.staggeredDividerBuilder().addTo(recyclerView)
And in Java with:
StaggeredDividerDecoration.builder(context).addTo(recyclerView)