Skip to content

Instantly share code, notes, and snippets.

@imandaliya
Created September 15, 2018 11:37
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 imandaliya/c55950d89a43fdcc93ed5b6edc9fd7f1 to your computer and use it in GitHub Desktop.
Save imandaliya/c55950d89a43fdcc93ed5b6edc9fd7f1 to your computer and use it in GitHub Desktop.
// Smooth scroll grid view item to center using
private void smoothScrollToCenter(GridView gridView, View child) {
Rect rect = new Rect();
gridView.getGlobalVisibleRect(rect);
gridView.smoothScrollBy(child.getBottom() - gridView.getScrollY() - rect.centerY() + child.getHeight() / 2, 200);
}
// now call in setOnItemClickListener method
smoothScrollToCenter(gridViewColor, view);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment