Java – how to get the offset of recyclerview?

I want to save the location of recyclerview and reset it later. If only half of the top item is visible, what can I use to save this offset?

For the position I'm using: findfirstcompletelyvisibleitemposition()

To reset the location I'm using:

        ((linearlayoutmanager) recyclerView.getLayoutManager()).scrollToPositionWithOffset(position, offset);

But I'm not sure what to pass as an offset?

resolvent:

You must use linearlayoutmanager as

linearlayoutmanager manager = (linearlayoutmanager) recyclerView.getLayoutManager();
int position = manager.findFirstVisibleItemPosition();
View firstItemView = manager.findViewByPosition(position);
float Offset = firstItemView.getTop();

And get the position and offset of the first item in the current window

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>