title: Horizontal fling in vertical ScrollView
body: <p>I have a fragment that shows the statistic of my app, and I want it that when the user does a horizontal fling from left to rigth or right to left, change data from days to months, from months to years...</p>
  
  <p>The xml of my Fragment is the following:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res/com.devadvance.circulartest"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/ScrollViewProgreso"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="#55b5c2"
  tools:ignore="NewApi,UnusedNamespace" &gt;
  
  &lt;RelativeLayout
      android:id="@+id/RelativeLayoutProgreso"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="#55b5c2"
      android:orientation="vertical"
      android:paddingBottom="40dp" &gt;
  
      &lt;ImageView
          android:id="@+id/imgpqprogreso"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentTop="true"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="28dp"
          android:src="@drawable/iconoprogreso" /&gt;
  
      &lt;LinearLayout
          android:id="@+id/layoutprogreso"
          android:layout_width="match_parent"
          android:layout_height="200dp"
          android:layout_alignParentLeft="true"
          android:layout_marginTop="235dp"
          android:background="#55b5c2"
          android:orientation="vertical" &gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;TextView
          android:id="@+id/txtpqprogreso"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignBottom="@+id/imgpqprogreso"
          android:layout_alignParentRight="true"
          android:layout_marginBottom="-3dp"
          android:layout_marginRight="16dp"
          android:text="¿Por qué?"
          android:textColor="#394347" /&gt;
  
      &lt;TextView
          android:id="@+id/txmesprogreso"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/imgpqprogreso"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="32dp"
          android:text="MAYO"
          android:textColor="#394347"
          android:textSize="18sp" /&gt;
  
      &lt;TextView
          android:id="@+id/txtsemanaprogreso"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/txmesprogreso"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="2dp"
          android:text="SEMANA 2"
          android:textColor="#394347"
          android:textSize="18sp" /&gt;
  
      &lt;Button
          android:id="@+id/btnizq"
          android:layout_width="14dp"
          android:layout_height="14dp"
          android:layout_alignBottom="@+id/txtsemanaprogreso"
          android:layout_marginBottom="4dp"
          android:layout_marginRight="16dp"
          android:layout_toLeftOf="@+id/txtsemanaprogreso"
          android:background="@drawable/flecha" /&gt;
  
      &lt;Button
          android:id="@+id/btnderecha"
          android:layout_width="14dp"
          android:layout_height="14dp"
          android:layout_alignBottom="@+id/btnizq"
          android:layout_marginBottom="-2dp"
          android:layout_marginLeft="16dp"
          android:layout_toRightOf="@+id/txtsemanaprogreso"
          android:background="@drawable/flecha" /&gt;
  
      &lt;TextView
          android:id="@+id/porcentajetrabajo"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignBottom="@+id/porcentajerojo"
          android:layout_marginBottom="6dp"
          android:layout_marginLeft="8dp"
          android:layout_toRightOf="@id/porcentajerojo"
          android:text="TRABAJO"
          android:textColor="#394347"
          android:textSize="18sp" /&gt;
  
      &lt;ImageView
          android:id="@+id/indicadoramarillo"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/indicadornaranja"
          android:layout_marginRight="20dp"
          android:layout_marginTop="20dp"
          android:layout_toLeftOf="@+id/porcentajeamarillo"
          android:src="@drawable/indicadoramarillo" /&gt;
  
      &lt;TextView
          android:id="@+id/porcentajeamarillo"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/porcentajerojo"
          android:layout_below="@id/porcentajerojo"
          android:layout_marginTop="14dp"
          android:text="TextView"
          android:textColor="#394347"
          android:textSize="44sp" /&gt;
  
      &lt;TextView
          android:id="@+id/porcentajedescanso"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignBottom="@+id/porcentajeamarillo"
          android:layout_alignLeft="@+id/porcentajetrabajo"
          android:layout_marginBottom="6dp"
          android:text="DESCANSO"
          android:textColor="#394347"
          android:textSize="18sp" /&gt;
  
      &lt;TextView
          android:id="@+id/porcentajerojo"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_above="@+id/indicadoramarillo"
          android:layout_centerHorizontal="true"
          android:text="TextView"
          android:textColor="#394347"
          android:textSize="44sp" /&gt;
  
      &lt;ImageView
          android:id="@+id/indicadornaranja"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/layoutprogreso"
          android:layout_marginBottom="4dp"
          android:layout_marginRight="20dp"
          android:layout_toLeftOf="@+id/porcentajerojo"
          android:src="@drawable/indicadornaranja" /&gt;
  
      &lt;ImageView
          android:id="@+id/imgllama"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/porcentajeamarillo"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="40dp"
          android:src="@drawable/llama" /&gt;
  
      &lt;TextView
          android:id="@+id/kcalprogreso"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/imgllama"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="10dp"
          android:text="TextView"
          android:textColor="#394347"
          android:textSize="44sp" /&gt;
  
      &lt;TextView
          android:id="@+id/txtkcalquemadas"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/kcalprogreso"
          android:layout_centerHorizontal="true"
          android:text="KCAL QUEMADAS"
          android:textColor="#394347"
          android:textSize="18sp" /&gt;
  
      &lt;ImageView
          android:id="@+id/imgsensacionprogreso"
          android:layout_width="match_parent"
          android:layout_height="120dp"
          android:layout_below="@+id/txtkcalquemadas"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="28dp"
          android:src="@drawable/regular" /&gt;
  
      &lt;TextView
          android:id="@+id/sensacionmedia"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/imgsensacionprogreso"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="16dp"
          android:text="SENSACIÓN MEDIA"
          android:textColor="#394347"
          android:textSize="18sp" /&gt;
  
      &lt;TextView
          android:id="@+id/txtsensacionprogreso"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/sensacionmedia"
          android:layout_centerHorizontal="true"
          android:text="TextView"
          android:textColor="#394347"
          android:textSize="44sp" /&gt;
  
       &lt;/RelativeLayout&gt;
  
      &lt;/ScrollView&gt;
  </code></pre>
  
  <p>And the code I'm using to detect the horizontal Fling is the following:</p>
  
  <pre><code>private final GestureDetector gdt = new GestureDetector(new GestureListener());
  
    private class GestureListener extends SimpleOnGestureListener {
  
        private static final int SWIPE_MIN_DISTANCE = 120;
          private static final int SWIPE_THRESHOLD_VELOCITY = 200;
  
          @Override
          public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                  float velocityY) {
  
              if(e1.getX() - e2.getX() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) {
                   Toast.makeText(getActivity(), "left", Toast.LENGTH_SHORT).show();
  
  
              }  else if (e2.getX() - e1.getX() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) {
                   Toast.makeText(getActivity(), "right", Toast.LENGTH_SHORT).show();
              }
  
              return false;
          }
  
       @Override
       public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
               float arg3) {
           return false;
       }
  
  
  
     }
  </code></pre>
  
  <p>And at onCreateView:</p>
  
  <pre><code>layoutpro.setOnTouchListener(new View.OnTouchListener() { 
  
  
      @Override
      public boolean onTouch(View arg0, final MotionEvent event) {
          // TODO Auto-generated method stub
          gdt.onTouchEvent(event);
           switch (event.getAction()) 
           {
               case MotionEvent.ACTION_DOWN:
                   break;
               case MotionEvent.ACTION_UP:
                      // Allow ScrollView to intercept touch events.
                      break;
           }
       return true;
      }
  
  });
  </code></pre>
  
  <p>Where layoutpro is </p>
  
  <pre><code>layoutpro = (RelativeLayout) view.findViewById(R.id.RelativeLayoutProgreso);
  </code></pre>
  
  <p>The fling gesture works but only sometimes, because most of the time it detects it as a vertical scroll movement, so, what could I do to keep both gestures working fine?</p>