0

I have two grid view, I need synchronize it, when I scrolling one, second must scrolling the same. I did so:

gvMain1.setOnScrollListener(new OnScrollListener(){
            @Override public void onScroll(AbsListView arg0, int arg1, int arg2, int arg3) 
            {
                gvMain2.setSelection(arg1);
            }
            @Override public void onScrollStateChanged(AbsListView arg0, int arg1) {}
            }); 

But when I scrolling, I get delta near one row difference in height, I think it because first grid move, but not enough for switch ti next position. How can I fix it?

Ivan
  • 181
  • 1
  • 2
  • 11

1 Answers1

1

This is not easy to do. I attempted this and eventually gave up. The GridView does not support all the same stuff that ListView supports, which is what makes this so difficult. You could crack open the android ListView source code and try and replicate what they do. Or just switch to using a list view if that will suite your needs.

For gridview you can do some magic to get the position. See How to get scroll position from GridView?

For grid view I never found a way to actually make it scroll exactly to the right place. It would only scroll item by item.

For a list view see this post: Android getting exact scroll position in ListView

There is a good post on this topic here as well: Android: Synchronized scrolling of two different views

Community
  • 1
  • 1
Nathan
  • 1,627
  • 12
  • 12