Premkumar Manipillai
Premkumar Manipillai

Reputation: 2151

Imageview single and double tap in android?

I have a Imageview in Android and i need to show a popup while single tap over the image and also need to zoom the image while two finger cross.

I tried with bellow code. can you please any one help me.

Thanks.

image = (ImageView) findViewById(R.id.image);
GestureDetector gdt = new GestureDetector(new GestureListener());


    image.setOnTouchListener(new OnTouchListener() {
                @Override
                public boolean onTouch(final View view, final MotionEvent event) {
                    gdt.onTouchEvent(event);
                    return true;
                }
            });



    private static final int SWIPE_MIN_DISTANCE = 120;
    private static final int SWIPE_THRESHOLD_VELOCITY = 200;

        private class GestureListener extends GestureDetector.SimpleOnGestureListener {
            @Override
            public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {                
                    return false; // Right to left
                }  else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {              
                    return false; // Left to right
                }

                if(e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {                
                    return false; // Bottom to top
                }  else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {                
                    return false; // Top to bottom
                }
                return false;
            }
        }

Upvotes: 1

Views: 180

Answers (1)

Bob
Bob

Reputation: 13850

Would you mind using a library from Chris Banes himself, for zooming the ImageView?

https://github.com/chrisbanes/PhotoView

Upvotes: 1

Related Questions