There is an array with links to images. There is an ImageView. Can we somehow get to process the sheet turning the left and right and then change the image to the desired one from the array? Interested in the implementation of the gesture turning.

    2 answers 2

    We can, using the onFling method:

     public class MyActivity extends Activity { private void onCreate() { final ImageView iv = (ImageView) findViewById(R.id.image_view); iv.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(final View v, final MotionEvent e) { gd.onTouchEvent(e); return true; } }); } private final GestureDetector gd = new GestureDetector(new GestureListener()); private static final int DISTANCE = 100; private static final int VELOCITY = 200; private class GestureListener extends SimpleOnGestureListener { @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if(e1.getX() - e2.getX() > DISTANCE && Math.abs(velocityX) > VELOCITY) { // Справа налево return false; } else if (e2.getX() - e1.getX() > DISTANCE && Math.abs(velocityX) > VELOCITY) { // Слева направо return false; } return false; } } } 

      Gallery not suitable?