This is a follow-up to my previous question.
In my app I\'m trying to have an horizontal RecyclerView
that automatically snaps to the center item. To do
RecyclerView
has own rules about ItemDecoration
. He thinks about them as a part of the item itself. You can think, what your decoration
(even if it's just a padding
) is part of your my_item.xml
itself.
LinearSnapHelper
uses methods like LayoutManager.getDecoratedMeasuredWidth()
to determine center of the view. And that's from where the problem occurs. It sees your first item much larger than you think, so it's center for the first view is acutally in (padding + view.getWidth()) / 2
. It is much farther than center for the second view, which is normal view.getX() + view.getWidth() / 2
.