title: How to synchronize two scrollview in Android?
body: <p>I have two horizontal <code>scrollview</code>, and want to keep them always at the same position / distance. If user scrolls one, need to scroll programmatically the other. The challenge is, that an infinite loop will occur. One will raise the other, other will raise first. How can I set a state, indicate that a user initiated scroll is still in progress? So other <code>scrollview</code> should not execute the programmatic scroll.</p>
  <p>One of them is a <code>HorizontalScrollView</code> other is a <code>RecyclerView</code>.</p>
  <p>Tried solutions like below, without any success:</p>
  <pre><code>horizontalScrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
          @Override
          public void onScrollChanged() {
  
              if (programmaticScrollEnable) {
                  programmaticScrollEnable = false;
                  // do programmatic scrolling here
                  programmaticScrollEnable = true;
              }
          }
      });        
  </code></pre>
  <p>Tried to change state in <code>onScrollStateChanged</code> method:</p>
  <pre><code>@Override
  public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
      super.onScrollStateChanged(recyclerView, newState);
  
      /*if (newState == RecyclerView.SCROLL_STATE_IDLE) {
          MainActivity.programmaticScrollEnable = true;
      }*/
  }
  </code></pre>