Hello,
Welcome to our Microsoft Q&A platform!
You can try to store the scroll postion in the OnPause method of the Activity, then get the position and scroll to previouse position in OnResume method.
public class MainActivity : AppCompatActivity
{
int lastOffset, lastPosition;
RecyclerView recyclerView;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
SetContentView(Resource.Layout.activity_main);
recyclerView = FindViewById<RecyclerView>(Resource.Id.recycler);
...
}
protected override void OnPause()
{
base.OnPause();
View topView = (recyclerView.GetLayoutManager() as LinearLayoutManager).GetChildAt(0);
if (topView != null)
{
lastOffset = topView.Top;
lastPosition = (recyclerView.GetLayoutManager() as LinearLayoutManager).GetPosition(topView);
}
}
protected override void OnResume()
{
base.OnResume();
if ((recyclerView.GetLayoutManager() as LinearLayoutManager) != null && lastPosition > 0)
{
(recyclerView.GetLayoutManager() as LinearLayoutManager).ScrollToPositionWithOffset(lastPosition, lastOffset);
}
}
}
Best Regards,
Jessie Zhang
---
If the response is helpful, please click "Accept Answer" and upvote it.
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.