Android: how to make a wide-angle navigation screen

I use the Gesture Listner to navigate the Swipe screen. But it is not so convenient that I need to scroll several times to go to the next or previous screen. What are the correct values โ€‹โ€‹for Velocity, Off path and Min Distance.

Below is my code:

private static final int SWIPE_MIN_DISTANCE = 50; private static final int SWIPE_MAX_OFF_PATH = 300; private static final int SWIPE_THRESHOLD_VELOCITY = 200; class MyGestureDetector extends SimpleOnGestureListener { @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) return false; // right to left swipe if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { viewFlipper.setInAnimation(slideLeftIn); viewFlipper.setOutAnimation(slideLeftOut); viewFlipper.showNext(); configDisplay(); } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { viewFlipper.setInAnimation(slideRightIn); viewFlipper.setOutAnimation(slideRightOut); viewFlipper.showPrevious(); configDisplay(); } } catch (Exception e) { // nothing } return false; } } 
+4
source share
2 answers

I recently implemented an application that used flinging and started with SimpleOnGestureListener, just like your example. I recorded speed and displacement on each pass and tested on my device to find what I thought was the right value.

But . I highly recommend you take a look at the ViewPager, which is available in the package.

About ViewPager with a link to an example.

0
source

Source: https://habr.com/ru/post/1332939/


All Articles