Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Change this:</strong></p> <pre><code>@Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { boolean result = false; try { float diffY = e2.getY() - e1.getY(); float diffX = e2.getX() - e1.getX(); ------&gt; if (Math.abs(diffX) &gt; Math.abs(diffY)) { &lt;------ if (Math.abs(diffX) &gt; SWIPE_THRESHOLD &amp;&amp; Math.abs(velocityX) &gt; SWIPE_VELOCITY_THRESHOLD) { if (diffX &gt; 0) { onSwipeRight(); } else { onSwipeLeft(); } } } else {..... </code></pre> <p><strong>to this:</strong></p> <pre><code>@Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { boolean result = false; try { float diffY = e2.getY() - e1.getY(); float diffX = e2.getX() - e1.getX(); ------&gt; if (Math.abs(diffX) &gt; Math.abs(diffY) - 50) { &lt;------ if (Math.abs(diffX) &gt; SWIPE_THRESHOLD &amp;&amp; Math.abs(velocityX) &gt; SWIPE_VELOCITY_THRESHOLD) { if (diffX &gt; 0) { onSwipeRight(); } else { onSwipeLeft(); } } } else {..... </code></pre> <p>This will <strong>allow you to swipe at a little more than a diagonal</strong> and still be regestured as a side to side swipe. </p> <p>This will also make you have to swipe more directly upward or downward. </p> <p>If you do <strong>not</strong> want to respond to upward swipes, you can just do this:</p> <pre><code>@Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { boolean result = false; try { float diffX = e2.getX() - e1.getX(); if (Math.abs(diffX) &gt; SWIPE_THRESHOLD &amp;&amp; Math.abs(velocityX) &gt; SWIPE_VELOCITY_THRESHOLD) { if (diffX &gt; 0) { onSwipeRight(); } else { onSwipeLeft(); } } } catch (Exception exception) { exception.printStackTrace(); } return result; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload