LinearSnapHelper doesn't snap on edge items of RecyclerView

前端 未结 1 709
感情败类
感情败类 2021-01-05 04:43

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

相关标签:
1条回答
  • 2021-01-05 05:20

    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.

    0 讨论(0)
提交回复
热议问题