1

i am new in android and working a comic application. i am using this code visit https://github.com/sephiroth74/ImageViewZoom for pinch zoom . and working it very fine.

but i am trying to go to next and previous image by swipe . but i am unable . this is my code which is OK for button and now i want to add swipe method .

next.setOnClickListener( new OnClickListener() {


        public void onClick( View v ) {
            selectnextImage();
        }
    } );

     pre.setOnClickListener( new OnClickListener() {
        public void onClick( View v ) {
            selectpreImage();
        }
    } );

thank u please any expert give me a bit time .

Rahul Rawat
  • 999
  • 2
  • 17
  • 40
  • Have you thought about a [ViewPager](http://developer.android.com/reference/android/support/v4/view/ViewPager.html)? – kentcdodds Oct 31 '12 at 16:37
  • Thank you . sorry , i have no knowledge about viewpager. may you create a code for me by viewpager add in my code. thank you sir – Rahul Rawat Nov 01 '12 at 07:06

2 Answers2

1

You can detect fling gestures on your main view like this:

final GestureDetector detector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        if(velocityX > 0) {
            selectnextImage();
        }
        else {
            selectpreImage();
        }
        return true;
    }
});

view.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if(event.getPointerCount() == 1) {
            if(mimage.getScale() == 1f) {
                detector.onTouchEvent(event);
                return true;
            }
            else {
                return false;
            }
        }
        else {
            return false;
        }
    }
});
Albireo
  • 10,977
  • 13
  • 62
  • 96
sdabet
  • 18,360
  • 11
  • 89
  • 158
  • this is correct for spiner . but it remove my previous library code of pinch zoom . may it possible to keep both code or any other way so i will do both pinch zoom with spiner . thank you – Rahul Rawat Nov 01 '12 at 08:41
  • hi fiddler, this code is skipping my pinchzoom code , but its looking good . may i use both code together pinchzoom and GestureDetector code ? please help me thank you – Rahul Rawat Nov 05 '12 at 13:43
  • I modified my code sample to detect swipe if there is ONLY 1 finger involved in the touch event. That may solve your problem – sdabet Nov 05 '12 at 14:34
  • Thank you , This is very nice, but is it possible ? we can do both activity together because one finger touch is also useful for scroll image . – Rahul Rawat Nov 05 '12 at 15:04
  • You mean vertical scrolling ? – sdabet Nov 05 '12 at 15:23
1

Try looking at the Android documentation for Implementing Lateral Navigation. This uses a ViewPager. I believe this is what Google recommends for something like this. You may not want to have the tabs there, but you can implement it without tabs. You can also implement it with a FragmentPagerAdapter.

kentcdodds
  • 27,113
  • 32
  • 108
  • 187