Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

synchronize two horizontal scroll view android

i have two horizontal scroll views each containing a linear layout item under it. how is it possible to synchronize the scroll, when either of it is scrolled, the other is also automatically scrolled. any help?

like image 776
i_raqz Avatar asked Oct 10 '22 15:10

i_raqz


2 Answers

What you could do is on the onTouch of the first Horizontal Scroll view, record the X position that it started with for an action of Down. Then when you have an action of Move, record the change in the X position. Then you can call the second horizontal scroll view's scrollBy (deltaX, 0). On an action of Up or Cancel, make sure to reset your state variables.

I've done this with a List View scrolling a vertical scroll, just using Y positions instead of X. Here is my code to accomplish this. The concurrentScroller is my vertical view.

if(concurrentScroller != null) {
            int deltaY = (int) (startTouchConcurrentY - ev.getY());
            startTouchConcurrentY = ev.getY();
            concurrentScroller.scrollBy(0, deltaY);                             
        } 
like image 180
C Nick Avatar answered Oct 14 '22 01:10

C Nick


I would implement onScrollListener for each of the views to call scrollTo on the other.

like image 36
Alexandru Cristescu Avatar answered Oct 14 '22 01:10

Alexandru Cristescu