Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to make ScrollTo on Android show the group header?

When using a ListView with grouping on, I'd like to be able to scroll the ListView so that the header of a particular group ends up on the top of the screen. This is easy to do on iOS using the built in ScrollTo method simply by calling it with the scroll target set to the first element in the target group (presumably because iOS always keeps a group header at the top at all times) but on Android the same call results in the first element being at the very top of the view with the header just slightly above it (off the screen/out of view). Please see attached screenshots and attached sample app.

How can I make the ListView scroll on Android like it does on iOS? I started looking into copying/forking the vanilla Xamarin.Forms.Android ListViewRenderer and tweaking the index handling of the OnScrollToRequested method but that made me feel very queasy.

For illustration, a couple of workarounds I had considered:

  • Call ScrollTo(target , ScrollToPosition.Center, true) rather than ScrollTo(target , ScrollToPosition.Start, true) - the group header will always be visible after the scroll, albeit with some space above it
  • Call ScrollTo but target the last element of the previous group - this will leave a little bit of space at the top still


Sign In or Register to comment.