Sheehan Alam
Sheehan Alam

Reputation: 60899

How can I create horizontal view scrolling like the News & Weather app?

Android News & Weather app lets you swipe to reveal another view, just like the iPhone. Can someone show me an example of how this is done?

It is not a ViewFlipper attached to a GestureDetector.

Upvotes: 0

Views: 1745

Answers (2)

Jon O
Jon O

Reputation: 6591

You can now do this out-of-the-box in the Android Compatibility library with a ViewPager: http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html?m=1

ViewPager slides between Fragments much the same way ListViews scroll up and down with views.

If you're not interested in scrolling the tabs, there's an example in the SDK that uses a TabHost (instead of making the tabs themselves scrollable left-to-right), but you need not use a TabHost. You could, if you wanted horizontally-scrolling tabs, use a HorizontalScrollView with some buttons in it.

For an approach that doesn't use the compatibility lib, or fragments, see here: https://github.com/olibye/AndroViews

Upvotes: 1

Romain Guy
Romain Guy

Reputation: 98501

It is a custom view, you can see how it's done in Launcher by looking at Workspace.java in packages/apps/Launcher2 at android.git.kernel.org.

Upvotes: 1

Related Questions