title: Android swipe left and right in RelativeLayout
body: <p>I am trying to implement swipe left or right in my RelativeLayout. I wrote some code but could not get swipe left or right working. I am using GestureDetector
  this is a my source</p>
  
  <pre><code>private GestureDetector gesturedetector = null;
  private RelativeLayout swipelayout;
  
  @SuppressLint("UseValueOf")
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
  
      View rootView = inflater.inflate(R.layout.strada_menu_result_loadmore,
              container, false);
  
  
      swipelayout = (RelativeLayout) rootView.findViewById(R.id.swipelayout);
  
      gesturedetector = new GestureDetector(new MyGestureListener());
      swipelayout.setOnTouchListener(new OnTouchListener() {
  
          @Override
  
          public boolean onTouch(View v, MotionEvent event) {
  
          gesturedetector.onTouchEvent(event);
  
          return true;
  
          }
  
          });
  
  
  
  
      return rootView;
  
  }
  
  
  public boolean dispatchTouchEvent(MotionEvent ev){
  
  
  
      return gesturedetector.onTouchEvent(ev);
  }
  
  
  
  class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
  
      private static final int SWIPE_MIN_DISTANCE = 150;
  
      private static final int SWIPE_MAX_OFF_PATH = 100;
  
      private static final int SWIPE_THRESHOLD_VELOCITY = 100;
  
      @Override
      public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
              float velocityY) {
  
          float dX = e2.getX() - e1.getX();
  
          float dY = e1.getY() - e2.getY();
  
          if (Math.abs(dY) &gt;= SWIPE_THRESHOLD_VELOCITY
                  &amp;&amp; Math.abs(velocityX) &gt;= SWIPE_THRESHOLD_VELOCITY &amp;&amp;
  
                  Math.abs(dX) &gt;= SWIPE_MIN_DISTANCE) {
  
              if (dX &gt; 0) {
  
                  Toast.makeText(getActivity(), "Right Swipe",
                          Toast.LENGTH_SHORT).show();
  
              } else {
  
                  Toast.makeText(getActivity(), "Left Swipe",
                          Toast.LENGTH_SHORT).show();
  
              }
  
              return true;
  
          }
          return false;
  
      }
  }
  </code></pre>
  
  <p>what am i doing wrong? if anyone knows solution please help me
  thanks</p>