I've implemented this on a picture slideshow app that I will publish
soon.
The principle is to use a GestureDetector which is set as the manager
of touch events of your Activity. Your activity can then implement an
OnGestureListener to react to specific gestures.
Here is some code extracted from my app :
import android.view.GestureDetector.OnGestureListener;
private class SlideShow implements OnGestureListener {
private GestureDetector mGestureScanner;
@Override
protected void onCreate(Bundle savedInstanceState) {
// [...]
mGestureScanner = new GestureDetector(this);
// [...]
}
@Override
public boolean onTouchEvent(MotionEvent me) {
return mGestureScanner.onTouchEvent(me);
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float
velocityX,
float velocityY) {
if (velocityX < 0) {
goForward();
return true;
} else if (velocityX > 0) {
goBack();
return true;
}
return false;
}
}
For the sliding effect, I have used a ViewFlipper and 3 ImageViews.
I defined in the apps resources 4 animations :
Going forward :
- translation from center to left : make the current page go away
(out)
- translation from right to center : make the next page come (in)
Going backward
- translation from center to right : make the current page go away
(out)
- translation from left to center : make the previous page come (in)
Depending on the direction of the fling, I set both in and out
animations of the ViewFlipper to the corresponding couple of forward
or backward animations.
I use 3 ImageViews so that my previous and next page can be preloaded
before the user decides to fling, otherwise the time between fling and
animation can be quite long if the next/previous view is long to
initialise.
Once the animation is finished, I rotate the role of each view and
preload the new next or previous image in the view that is now 2 pages
away from the current.
I hope this helps.
Nivek
On 20 août, 07:59, Grahamdroid <[email protected]> wrote:
> So my application has a large amount of textual data. Up until this
> point I've been using forward and back buttons to navigate from
> section to section. I was impressed with the horizontal scrolling of
> the Ebook reader from Alkido that is available on the store which uses
> a horizontal fling gesture to flip the pages. Does anyone have any
> experience doing something like this? I've done it a number of ways,
> but none seem to be very smooth or efficient. Thanks in advance.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---