title: Swipe/Fling tab-changing in conjunction with ScrollView?
body: <p>The best I could find on this particular issue (although I do not use a Gallery): <a href="https://stackoverflow.com/questions/3171452/scrollview-and-gallery-interfering">ScrollView and Gallery interfering</a> - doesn't really give a specific answer though. And my implementation does not use a Gallery, obviously.</p>
  
  <p><strong>Jump down to the next bold part for the interesting part</strong></p>
  
  <p>So I got Fling/Swipe/Flick/whatever you want to call it to work a while ago on my application. Inspiration was gathered from a couple of different places, some of them being "basic gesture detection" here on Stack Overflow ( <a href="https://stackoverflow.com/questions/937313/android-basic-gesture-detection">Fling gesture detection on grid layout</a> ), Code Shogun ( <a href="http://www.codeshogun.com/blog/2009/04/16/how-to-implement-swipe-action-in-android/" rel="nofollow noreferrer">http://www.codeshogun.com/blog/2009/04/16/how-to-implement-swipe-action-in-android/</a> ) and Developing Android ( <a href="http://developingandroid.blogspot.com/2009/09/implementing-swipe-gesture.html" rel="nofollow noreferrer">http://developingandroid.blogspot.com/2009/09/implementing-swipe-gesture.html</a> ), but I do not use a ViewFlipper in my application. When a fling occurs I simply change the tab (wrapping around at the ends).</p>
  
  <p>Now, some of my tabs contain ScrollViews. These ScrollViews obviously respond to up/down scrolls in order to let you view all data inside it, no surprise there.
  The issue is that it would appear the 'scroll' function of these ScrollViews overwrite my fling gesture. I cannot fling inside a ScrollView (scroll just fine), but it works flawlessly outside them (on the same tab, on other views such as TableRow or whatever).</p>
  
  <p>I had a quick look at <a href="http://blog.velir.com/index.php/2010/11/17/android-snapping-horizontal-scroll/" rel="nofollow noreferrer">http://blog.velir.com/index.php/2010/11/17/android-snapping-horizontal-scroll/</a> too, which provides a way to implement HorizontalScrollView. But it still handles gestures through a class that extends SimpleOnGestureListener (and overwrites onFling), which is the same implementation as I have (which leads me to believe it won't really help).
  Source code for ScrollView from Google: <a href="http://google.com/codesearch/p?hl=en#uX1GffpyOZk/core/java/android/widget/ScrollView.java&amp;d=3" rel="nofollow noreferrer">http://google.com/codesearch/p?hl=en#uX1GffpyOZk/core/java/android/widget/ScrollView.java&amp;d=3</a></p>
  
  <p><strong>Is there any way to have my implementation of Swipe and ScrollView working together effortlessly?</strong></p>
  
  <p>This is where the problem lies, I guess. ScrollView.java also uses a method called onTouchEvent and the documentation for the onTouchEvent for Activity states:</p>
  
  <blockquote>
    <p>"Called when a touch screen event was
    not handled by any of the views under
    it. This is most useful to process
    touch events that happen outside of
    your window bounds, where there is no
    view to receive it."</p>
  </blockquote>
  
  <p>So the ScrollView does "override" it - what do I do? Is there no way to ensure both are checked? My onTouchEvent which is not hit when the onTouchEvent is handled by the ScrollView:</p>
  
  <pre><code>@Override
  /** Used for swipe gestures */
  public boolean onTouchEvent(MotionEvent event) {
      if (gestureDetector.onTouchEvent(event))
          return true;
      else
          return false;
  }
  </code></pre>
  
  <p>More general source code below, it's probably not very vital. The gestureDetector inside my Tabs class with its associated listener: </p>
  
  <pre><code>    // Gestures
      gestureDetector = new GestureDetector(new MyGestureDetector());
      gestureListener = new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
              if (gestureDetector.onTouchEvent(event)) {
                  return true;
              }
              return false;
          }
      };
  </code></pre>
  
  <p>My gesture class which is a nested class of my Tabs class (which extends TabActivity) - it's the same as any other code you will find on this subject:</p>
  
  <pre><code>/** GestureDetector used to swipe between classes */
  class MyGestureDetector extends SimpleOnGestureListener {
      TabHost tabHost = getTabHost(); 
  
      @Override
      public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
          try {
              if (Math.abs(e1.getY() - e2.getY()) &gt; SWIPE_MAX_OFF_PATH) return false;
              if (e1.getX() - e2.getX() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) {
                  // my tab code
                  return true;
              } else if (e2.getX() - e1.getX() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) {
                  // my tab code
                  return true;
              }
          } catch (Exception e) {
              Log.e("MyGestureDetector onFling", e.toString());
          }
          return false;
      }
  }
  </code></pre>