Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's tricky to get scroll and swipe tracking working on Android, while using <code>ViewAnimator</code> or its subclasses.</p> <p>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 <code>FrameLayout</code> and after in or out animation is executed, other views' visibility is set to <code>View.GONE</code> to hide them from showing up under/over your current <code>View</code>.</p> <p>The Launcher and the Gallery application are actually doing the functionality you want, by using a different approach. They track the user touch input (<code>onTouchEvent()</code>), on <code>MotionEvent.ACTION_MOVE</code> they perform animations manually and on <code>MotionEvent.ACTION_UP</code> snap to the appropriate view, just like in the iPhone.</p> <p>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 <a href="http://android.git.kernel.org/?p=platform/packages/apps/Gallery3D.git;a=blob;f=src/com/cooliris/media/GridInputProcessor.java;hb=eclair" rel="nofollow noreferrer">Gallery3D</a> or <a href="http://android.git.kernel.org/?p=platform/packages/apps/Launcher.git;a=blob;f=src/com/android/launcher/Workspace.java;hb=eclair" rel="nofollow noreferrer">Launcher</a>'s source code.</p> <p>One other way to get nice horizontal scrolling is to use <code>HorizontalScrollView</code>. You have to figure out a way to recycle your views, like you would with a <code>ListView</code> 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.</p> <p>Hope that helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload