How to make an Android view that flips between views on swipe/fling

emmby picture emmby · Feb 21, 2011 · Viewed 40.4k times · Source

I'd like to make a view in my Android app that flips between multiple views on a swipe/fling. I'd like it to behave more or less like the Android Launcher behaves when flipping between views. In particular,

  1. It should flip views on swipe.
  2. Generally a swipe will flip between one view and the next. It should not fling across all of the views.
  3. If you swipe slowly, you should see the views dragging as you're swiping, eg. the way the Launcher does it.

I tried using a ViewFlipper with a GestureOverlayView as per Romain Guy's blog post here, but there's no indicator to the user as they're swiping. This makes discoverability difficult, which is presumably why Launcher does it the way they do.

I tried using a Gallery object, but when I swipe from left to right, there's a certain amount of momentum that flings the users through all the views rather than just taking them to the next view.

Is there a good way to accomplish what I'm trying to do?

Answer

binW picture binW · Aug 25, 2011

I know this is an old question but ViewPager is created for this exact same purpose. ViewPager is part of android compatibility package and more can be found at http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html