title: End up activity on swipe right?
body: <p>I have to finish <code>Activity</code> when user offer a right swipe anywhere in the screen. I have tried with <a href="https://stackoverflow.com/a/12938787/4817630"><code>GestureDetector</code></a> and that is works fine if there is neither <code>ScrollView</code> nor <code>RescyclerView</code> exists in the <code>Activity</code> and in addition views that have <code>onClickListener</code> also doesn't allow to detect swipe over them. So I had tried a different way by overlaying a view into the layout at the top of all them programmatically then tried to detect the swipe event over it.</p>
  
  <pre><code>private void swipeOverToExit(ViewGroup rootView) {
  
          OverlayLayout child = new OverlayLayout(this);
  
          ViewGroup.LayoutParams layoutParams =
                  new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
  
          child.setLayoutParams(layoutParams);
  
          rootView.addView(child);
  
  }
  </code></pre>
  
  <p><strong>OverlayLayout</strong> </p>
  
  <pre><code>public class OverlayLayout extends RelativeLayout {
  
      private float x1, x2;
      private final int MIN_DISTANCE = 150;
  
      public OverlayLayout(Context context) {
          super(context);
      }
  
      public OverlayLayout(Context context, AttributeSet attrs) {
          super(context, attrs);
      }
  
      public OverlayLayout(Context context, AttributeSet attrs, int defStyleAttr) {
          super(context, attrs, defStyleAttr);
      }
  
      @TargetApi(Build.VERSION_CODES.LOLLIPOP)
      public OverlayLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
          super(context, attrs, defStyleAttr, defStyleRes);
      }
  
  
      @Override
      public boolean onInterceptTouchEvent(MotionEvent event) {
          /*
           * This method JUST determines whether we want to intercept the motion.
           * If we return true, onTouchEvent will be called and we do the actual
           * logic there.
           */
  
          final int action = MotionEventCompat.getActionMasked(event);
  
          Logger.logD("Intercept===", action + "");
  
  
          // Always handle the case of the touch gesture being complete.
          if (action == MotionEvent.ACTION_DOWN) {
              return true; // Intercept touch event, let the parent handle swipe
          }
  
          Logger.logD("===", "Out side" + action + "");
  
  
          // In general, we don't want to intercept touch events. They should be
          // handled by the child view.
          return false;
      }
  
  
      @Override
      public boolean onTouchEvent(MotionEvent event) {
          switch (event.getAction()) {
              case MotionEvent.ACTION_DOWN:
                  x1 = event.getX();
                  break;
              case MotionEvent.ACTION_UP:
  
                  x2 = event.getX();
                  float deltaX = x2 - x1;
  
                  if (Math.abs(deltaX) &gt; MIN_DISTANCE) {
  
                      Logger.logD("Swipe Right===", MIN_DISTANCE + "");
                      return true;
  
                  } else {
  
                      Logger.logD("Tap===", "Tap===");
                      return super.onTouchEvent(event);
                  }
          }
  
          return true;
  
      }
  }
  </code></pre>
  
  <p>The logic is to intercept touch event to other view if swipe action performs over the <code>OverlayLayout</code> then further end up the <code>Activity</code>. However, now I can detect the swipe event on <code>OverlayLayout</code> but other views couldn't respond even though I had return  <code>return super.onTouchEvent(event);</code> in else condition of <code>onTouchEvent</code> as u can figure out there in my code. Any one please help me to make it . I'm pinned here and super excited to learn the trick :)</p>