Sync two horizontal scrolling

I have two horizontal scroll views, each of which contains a line layout element below it. how can you synchronize the scrolling, when any of them scrolls, the other also scrolls automatically. any help?

+4
source share
2 answers

What you can do is enable the onTouch of the first horizontal scroll view, write down the X position it started from for the Down action. Then, when you have the Move action, write down the change at position X. Then you can invoke the second horizontal scroll scrollBy (deltaX, 0). With the Up or Cancel action, make sure to reset the state variables.

I did this when the List List scrolls vertically, just using Y positions instead of X. Here is my code for this. The concurrentScroller parameter is my vertical view.

if(concurrentScroller != null) { int deltaY = (int) (startTouchConcurrentY - ev.getY()); startTouchConcurrentY = ev.getY(); concurrentScroller.scrollBy(0, deltaY); } 
+3
source

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

+1
source

All Articles