fling not working with TabActivity

I'm playing around with an app I have written whose main activity is a TabActivity. I was considering allowing the user to navigate between tabs with a fling gesture, but I find that I can only detect flings on one of my four tabs.

public class WSGesture extends TabActivity implements OnGestureListener {

private GestureDetector gestureScanner;

@Override onCreate(Bundle savedInstanceState) {

gestureScanner = new GestureDetector(this);
...
}

.
.
.
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
Log.v(TAG, "onFling called, velX: " + velocityX + ", velY: " + velocityY);

return true;  

}

public boolean onTouchEvent(MotionEvent me) {
return gestureScanner.onTouchEvent(me);

}

When I execute this code, I only see onFling being called when one particular tab is set as the current tab. For the other three, I get nothing. It's always the third out of four, if that matters.


One thing that has worked for me in the past is implementing onDown() and returning true...

When doing this though, be careful... I have found that the behavior when doing this is different between the 1.x and 2.x versions of Android when using your onGestureListener to handle other things like single clicks... so be sure to thoroughly test your app when making changes like this.

If you are only using onFling then you "should" be ok... but test it just to be safe.

链接地址: http://www.djcxy.com/p/16202.html

上一篇: Android:如何处理从左至右的滑动手势

下一篇: 抛出不能使用TabActivity