I want to save the position of my RecyclerView, then reset it later. If the top item is only halfway visible, what do I use to save this offset?
For the position I am using: findFirstCompletelyVisibleItemPosition()
To reset the position I am using:
((LinearLayoutManager) recyclerView.getLayoutManager()).scrollToPositionWithOffset(position, offset);
But I am not sure what to pass as the offset?
by override RecyclerView onScrolled (int dx,int dy) , you can get the scroll offset. but when you add or remove the item, the value may be wrong.
The basic methods for a successful implementation are: onCreateViewHolder: which deals with the inflation of the card layout as an item for the RecyclerView. onBindViewHolder: which deals with the setting of different data and methods related to clicks on particular items of the RecyclerView.
The Card Layout: The card layout is an XML layout which will be treated as an item for the list created by the RecyclerView.
Every time onDraw (…) is called, we go through all the Views there are in RecyclerView in a cycle and draw the passed drawable. However, the layout elements on your screen can be more complex than a list of identical elements. A screen can have: A.
You must use LinearLayoutManager
as this..
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 first item in current window.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With