6

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?

2 Answers 2

3

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); } 
Sign up to request clarification or add additional context in comments.

2 Comments

This solution doesn't work when flipping, the first view keeps going while as the second just move an deltaY movement. :(
1

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

3 Comments

Which views? There is no onScrollListener method for HorizontalScrollView.
scrollView.getViewTreeObserver().addOnScrollChangedListener(new OnScrollChangedListener(){...});
Hi Alexandru, any idea about this one ? stackoverflow.com/questions/58848391/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.