Skip to content

Instantly share code, notes, and snippets.

@chrisriesgo
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisriesgo/dd57ebfcd0d3218837b3 to your computer and use it in GitHub Desktop.
Save chrisriesgo/dd57ebfcd0d3218837b3 to your computer and use it in GitHub Desktop.
void SnapScroll ()
{
var roughIndex = (float)_scrollView.ScrollX / _scrollView.Width;
var targetIndex =
_deltaX < 0 ? Math.Floor (roughIndex)
: _deltaX > 0 ? Math.Ceil (roughIndex)
: Math.Round (roughIndex);
ScrollToIndex ((int)targetIndex);
}
void ScrollToIndex (int targetIndex)
{
var targetX = targetIndex * _scrollView.Width;
_scrollView.Post (new Runnable (() => {
_scrollView.SmoothScrollTo(targetX, 0);
}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment