views:

541

answers:

2

I'm interested in creating a horizontal scroll view that "snaps" to the viewed item, so only one item is ever shown at a time. The user can touch-drag left/right and will see previous/next views, switching to it if there's enough velocity. This interaction is exactly like what the new weather/news widget that comes with the Nexus One does for navigating between its "tabs".

Are there any existing view widgets that do this?

Update: found a copy of the news/weather widget (GenieWidget) and they seem to have implemented their own widget to accomplish this which they call com.google.android.apps.genie.geniewidget.ui.FlingableLinearLayout which is part of their own custom com.google.android.apps.genie.geniewidget.ui.TabView. As that source isn't available, that's not looking too hopeful a direction.

+4  A: 

Don't look at the News and weather implementation, it has a couple of flaws. You can however use the source code of the Home app (called Launcher or Launcher2), at android.git.kernel.org. The widget we use to do the scrolling on Home is in Workspace.java.

Romain Guy
Ah, thanks. That'll be much better than starting from scratch. I'm somewhat surprised that there aren't any pre-made generic ones yet, as it's a pretty popular form of interaction.
Steve Pomeroy
I agree it would be nice to make it a view/layout which will work with adapter.
Alex Volovoy
A: 

I am not aware of Nexus one but, i can suggest u the gallery view. It is perfectly apt one for your requirement according to your above explanation.

Kantesh
Yeah, gallery is close to what I'm looking for, but its physics allows for more "flinging" than I'm looking for here. I really am thinking more of what you see on the home screen (a full-screen switching between views). For smaller things with more uniform content, gallery is entirely correct.
Steve Pomeroy