Reputation: 26668
Anyone know of a library or method I can use to emulate the way the Android homescreens work?
What I mean is this:
A control that will take any number of sub-Views. It will only show one of those Views at a time, however, when the user drags their finger over the screen, it'll switch to the next or previous view, depending on which way the user dragged their finger.
I've seen a few examples (SwipeGestureListener comes to mind), but they don't work in the way I'd like. They require a swipe gesture, which means the widget doesn't move unless there is an actual swipe. For this reason, it's not readily obvious that the pages are switchable using this method.
Any information would be great.
Upvotes: 7
Views: 8963
Reputation: 6892
The control you mentioned above is called ViewPager - it's from Android Compatibility Package of Android. But the default Android ViewPager doesn't include a "pager indicator" control.
Don't worried. There are many open source library give you a "pager indicator" control along with ViewPager. IMHO, two of the best are:
android-viewflow: https://github.com/pakerfeldt/android-viewflow
Android-ViewPagerIndicator: https://github.com/JakeWharton/Android-ViewPagerIndicator
If you have time, it's good to check out many Android UI controls which included in "Android UI Patterns" app: https://market.android.com/details?id=com.groidify.uipatterns
Upvotes: 1
Reputation: 39894
This is probably what you need http://code.google.com/p/deezapps-widgets/.
Tried to use it in a project of mine but didn't work well with ListViews with a gradient as the background.
Upvotes: 5
Reputation: 33983
This link is the android source code. Workspace.java is what u will need. The workspace.java extends the ViewGroup and u can strip down the code to your needs..
Upvotes: 3
Reputation: 511
Check out ViewFlipper, ViewSwitcher etc. depending on your need.
http://developer.android.com/reference/android/widget/ViewFlipper.html
There are some neat samples included in the SDK.
For swipes and other gestures capture MotionEvents and act accordingly.
Upvotes: 0