It's tricky to get scroll and swipe tracking working on Android, while using ViewAnimator
or its subclasses.
They allow you to set in and out animations and start them at a given moment, but they work with discrete, either-this-or-the-other-view animations. They are actually using FrameLayout
and after in or out animation is executed, other views' visibility is set to View.GONE
to hide them from showing up under/over your current View
.
The Launcher and the Gallery application are actually doing the functionality you want, by using a different approach.
They track the user touch input (onTouchEvent()
), on MotionEvent.ACTION_MOVE
they perform animations manually and on MotionEvent.ACTION_UP
snap to the appropriate view, just like in the iPhone.
Unfortunately, this approach is actually more complicated than it looks like.
With the manual handling, you have to ensure that you are taking care of everything related to the touch input. This includes a lot of flag-raising, value-checking, event-delegating, etc.
If you want to get better acquainted with this, take a look at these classes from Gallery3D or Launcher's source code.
One other way to get nice horizontal scrolling is to use HorizontalScrollView
.
You have to figure out a way to recycle your views, like you would with a ListView
and you have to add the snap-to-view logic, but if you have to take care of a small number of views it could be the easiest approach.
Hope that helps.