RecyclerView Decorations
suggest changeVersions
[{“Name”:“3.0.x”,“GroupName”:null},{“Name”:“3.1.x”,“GroupName”:null},{“Name”:“3.2.x”,“GroupName”:null},{“Name”:“4.0”,“GroupName”:null},{“Name”:“4.0.3”,“GroupName”:null},{“Name”:“4.1”,“GroupName”:null},{“Name”:“4.2”,“GroupName”:null},{“Name”:“4.3”,“GroupName”:null},{“Name”:“4.4”,“GroupName”:null},{“Name”:“4.4W”,“GroupName”:null},{“Name”:“5.0”,“GroupName”:null},{“Name”:“5.1”,“GroupName”:null},{“Name”:“6.0”,“GroupName”:null},{“Name”:“7.0”,“GroupName”:null},{“Name”:“7.1”,“GroupName”:null}]
Syntax
- RecyclerView addItemDecoration(RecyclerView.ItemDecoration decoration)
- RecyclerView addItemDecoration(RecyclerView.ItemDecoration decoration, int index)
Parameters
Parameter | Details |
——— | —–– |
decoration| the item decoration to add to the RecyclerView
|
index | the index in the list of decorations for this RecyclerView
. This is the order in which getItemOffset
and onDraw
are called. Later calls might overdraw previous ones.
Remarks
Decorations are static
Since decorations are only drawn, it is not possible to add click listeners or other UI functionality to them.
Multiple decorations
Adding multiple decorations to a RecyclerView
will work in some cases, but there is currently no public API to take other possible decorations into account when measuring or drawing. You can get the view bounds or the view decorated bounds, where the decorated bounds are the sum of all the decoration offsets applied.
Other related topics:
Official javadoc
https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ItemDecoration.html