0

I want to develop something like the home screen of the Android's devices, where you can go from one main home screen to another by passing the finger across the screen. Something like the Android's photos gallery...

The way I'm doing it now is using Gallery:

private class PhotosGallery extends Gallery{

    public PhotosGallery(Context context) {
        super(context);
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        return super.onFling(e1, e2, 0, 0);
    }

}

But this way is not working very well: if you don't pass your finger all over the screen's width, it doesn't go to the next page (it kind of stops and comes back to the page you were before the interaction).

Any one knows another way?

Mech
  • 2,904
  • 3
  • 24
  • 29
Alesqui
  • 6,417
  • 5
  • 39
  • 43
  • Take a look at this question http://stackoverflow.com/questions/5071743/how-to-make-an-android-view-that-flips-between-views-on-swipe-fling – Frank Nov 18 '11 at 18:23

1 Answers1

2

This sounds like a job for ViewPager.

Quoting an Android developer blog post:

Whether you have just started out in Android app development or are a veteran of the craft, it probably won’t be too long before you’ll need to implement horizontally scrolling sets of views. Many existing Android apps already use this UI pattern, such as the new Android Market, Google Docs and Google+. ViewPager standardizes the implementation.

ViewPager was released as part of the Compatibility Package revision 3 and works with Android 1.6 upwards.

That blog post describes the basics, and you will find many questions and answers here on StackOverflow related to its use.

Community
  • 1
  • 1
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491