Linearsnaphelper Doesn't Snap On Edge Items Of Recyclerview
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 so, I've attached a LinearSn
Solution 1:
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
.
Post a Comment for "Linearsnaphelper Doesn't Snap On Edge Items Of Recyclerview"