使用scrollToPosition时如何将项目设置为RecyclerView的中心

时间:2017-04-05 07:10:22

标签: android android-recyclerview

我正在使用RecyclerView水平显示项目。

我希望当我使用scrollToPosition(位置)时,相应的项目出现在中心而不是左侧。

有没有人知道怎么做?我知道如何使用smoothScrollToPosition来做,但在这种情况下我需要使用scrollToPosition。

RecyclerView exemple

1 个答案:

答案 0 :(得分:5)

考虑使用scrollToPositionWithOffset(int position, int offset)并从左侧传递所需的偏移量。您可以使用父布局的宽度找到所需的偏移量(假设您使用的是水平回收器视图)。干杯:)

相关问题