views:

205

answers:

3

Hello everyone--

I'm pretty new to Android app development, and I've been playing around with swipe gestures using Android's SimpleOnGestureListener and a ViewFlipper. There are 3 children of the ViewFlipper, and each is a ScrollView. They're all dynamically populated when the Activity loads, and they don't change after that. The ScrollView is where the SimpleOnGestureListeners are attached.

Here's the layout I'm using:
+ViewFlipper
++ScrollView (x3, one for each page, each with the following:)
+++LinearLayout (vertical)
++++TextView
++++TableLayout (dynamically populated w/TableRows)
++++View

I extended the onFling method with the common tutorial code you can find anywhere online, and it works great--except when one of the ScrollViews doesn't contain enough content to scroll.

I've narrowed the problem down to touch detection by overriding and calling super on every one of the SimpleOnGestureListener's methods to add a print-to-log.

When I swipe on a page that scrolls, I get something full of "in onClick" "in onScroll" "in onFling" etc. On a page that's too short to scroll, I get "in onClick" "in onShowPress" "in onLongPress", and that's only if I'm touching the content within the too-short scrollview's children--if I touch elsewhere I get no events at all.

Ideas on what's wrong, or how to detect the swipe gesture no matter how big the ScrollView is?

EDIT: I've determined that when I run this on an Android 2.2 emulator, as opposed to the Android 2.1u1 DroidX emulator I've been using, it goes away. This is reproducible across multiple environments.

+1  A: 

Try setting android:fillViewport="true" in your layout xml for each of the ScrollViews. That tells the ScrollView to be as large as the view it's contained in.

Qberticus
Jon O
A: 

You may be trying out for the effect like I-phone swipe as per your explanation, is it so?

Ashay
That's roughly correct... I have a static frame at the top that I would like to stay put, and the views below I would like to swipe between. It works perfectly when the views are all big enough to scroll.
Jon O
A: 

I needed to create a new class that extended ScrollView, and used this:

@Override
public boolean onTouchEvent(MotionEvent event) {
    super.onTouchEvent(event);
    return gestureDetector.onTouchEvent(event);
}

@Override 
public boolean dispatchTouchEvent(MotionEvent ev){
    gestureDetector.onTouchEvent(ev);
    super.dispatchTouchEvent(ev); 
    return true;
} 

I have no idea why, but if I try to return anything but true in dispatchTouchEvent (the logical thing would have been to

return (gestureDetector.onTouchEvent(ev) || super.dispatchTouchEvent(ev)); 

if I understand properly), it doesn't work, and this does.

Jon O