Hello,
Generally, we could use the method getAdapterPosition
to get the position of items in RecyclerView.
However, in the official documentation getAdapterPosition, we could find that:
This method is deprecated.
This method is confusing when adapters nest other adapters. If you are calling this in the context of an Adapter, you probably want to call getBindingAdapterPosition() or if you want the position as RecyclerView sees it, you should call getAbsoluteAdapterPosition().
Therefore, if you want to get the absolute position in RecyclerView, you could use the method getAbsoluteAdapterPosition
.
Here is the documentation link: https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder#getAbsoluteAdapterPosition().
If you want to get the scrolling distance, you can refer to computeVerticalScrollOffset to get more details.
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.