venkat venkat - 6 months ago 85
Android Question

how to create swipe action for gridview images?

I want to create fling(swipe) action for gridview images.I implemented grid view images using this link
here when i clicked grid view images it will goes to full screen images.Now after display full image then swipe images left to right and right to left with finger touch. Here not use view flipper because here more images.Here which image is clicked that is display and swipe to right or left.


For that you can use GestureDetector and View.onTouchListener

Here is an extract from some code I used previously:

private int SWIPE_MIN_DISTANCE = 160;
private int SWIPE_MAX_OFF_PATH = 250;
private class MyGestureDetector extends SimpleOnGestureListener {
    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) {
            } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
                    && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
        } catch (Exception e) {
            // nothing
        return false;