views:

1070

answers:

3

I have implemented a slideshow in my Android app using . This works well except that I want to scroll to next image on a scroll gesture (now it just scrolls past few images before decelerating). I have couldn't find a appropriate way to do this, should I be using a FrameLayout instead ? How do I scroll to the next (or previous) image on scroll gesture ?

A: 

From your description it sounds like right now you have your slideshow implemented as a series of images in a scrollview, is that correct?

Rather than placing it in a scrollview and allowing that view to do the scrolling, you could display a single image and listen for a fling or scroll gesture on the image (see documentation). When you detect the gesture you could then manually change the image.

If you want it to animate the image coming onto the screen, you could use an animation.

Mayra
ohhorob
@ohhorob Heh, woops, sorry about that. I'm not sure what the link was supposed to be pointing to, but probably just the android docs: http://developer.android.com/reference/android/view/View.OnTouchListener.html
Mayra
A: 

the moment you post a question you realize the answer! I went from using Gallery to HorizontalScrollView back to using Gallery. Just shows my n00bness. Gallery solved my problem nicely. I have a custom class that extends Gallery and overrides onFling(...). In this reset the velocityX to say -300 or 300 depending on the direction, this results in scrolling to the next "page".

Ionic Walrus
A: 

This is what I ended up using

    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
        float velocityY) {
    // TODO Auto-generated method stub

    if (velocityX <= 0 ){
        // hack - send event to simulate right key press
        KeyEvent rightKey  = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT);
        this.onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, rightKey);

        rightKey = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_RIGHT);
        this.onKeyUp(KeyEvent.KEYCODE_DPAD_RIGHT, rightKey);            

    }else{
        // hack - send event to simulate left key press
        KeyEvent leftKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_LEFT);
        this.onKeyDown(KeyEvent.KEYCODE_DPAD_LEFT, leftKey);

        leftKey = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_LEFT);
        this.onKeyUp(KeyEvent.KEYCODE_DPAD_LEFT, leftKey);
    }


    // your callback activity if you have one:
    if( callbackActivity != null ){
        callbackActivity.didFlingGallery();
    }

    return true;
}
Sandeep Chayapathi