3

I have four images in the Gallery View. When we do swipe from left to right or right to left the Gallery View moves all the images i.e if I swipe from left to right from the first image then it will move to all the four images.

What I want is that when I swipe it should only move to the next image. Can someone let me know how is this possible?

Hope to get a reply soon.

Regards Sunil

sunil
  • 9,541
  • 18
  • 66
  • 88

3 Answers3

4

I accomplished this by creating a CustomGallery class that extends Gallery. I then Overrode the onFling method of Gallery. Inside the onFling method, simply return false. This will cause the Gallery to only move to the next image when onFling is called.

Ben W
  • 41
  • 1
  • The downside of this is that it doesn't feel smooth - when flinging, the animation is there but the photo returns back to the current photo instead of going next one. – AlikElzin-kilaka Jul 22 '12 at 10:37
3

You can implement this without using a Gallery: put an ImageView on your Layout and detect Swipes using GestureListener. On Left or right swipe, cycle through the imageList in appropriate direction and set the image in the ImageView. When you set the image, play appropriate slide left or slide right animation.

Community
  • 1
  • 1
Samuh
  • 36,316
  • 26
  • 109
  • 116
  • I found manipulating the default behavior of Gallery widget non-trivial; this is just an alternative. – Samuh Apr 15 '10 at 12:35
0

use a ViewFlipper concept with fling concept ... try using this comment

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY) 
{ 
    if (Math.abs(e1.getY() - e2.getY()) > 50) 
         return false; 

    if(e1.getX() - e2.getX() > 10 && Math.abs(velocityX) > 10) 
    { 
         vf.showNext();
    }  
    else if (e2.getX() - e1.getX() > 10 && Math.abs(velocityX) > 10) 
    { 
         vf.showPrevious();
    } 

    return false; 
}
biegleux
  • 13,179
  • 11
  • 45
  • 52