1

I am making an android app and it uses a GridView. I made a search button so people can go to a specefic position in the GridView. I am currently using:

gridview.smoothScrollToPosition(index);

But in that doesn't center the position to the middle of the GridView.
This is what I want in an illustration:
enter image description here

Actually the problem is that the GridView stops scrolling from the moment the correct item is visible. Which means it will have a different place when scrolling up or down.

Willis
  • 5,308
  • 3
  • 32
  • 61
Emiel Vandenbussche
  • 363
  • 1
  • 5
  • 12

2 Answers2

1

I have similar issues, so I manual compute it. v is the View to be centered:

   Rect rect = new Rect();
   mMediaGridView.getGlobalVisibleRect(rect);

   mMediaGridView.smoothScrollBy(v.getBottom()  - mMediaGridView.getScrollY()-rect.centerY()+v.getHeight()/2, 200);
Cimbali
  • 11,012
  • 1
  • 39
  • 68
0

This might be a duplicate of this problem: android: smoothScrollToPosition() not working correctly

I've experienced an issue like this before with listviews, I used setSelection() to solve it.

Community
  • 1
  • 1
AndroidEnthusiast
  • 6,557
  • 10
  • 42
  • 56