我在玩GestureDetector,注意在OSX上的模拟器上运行时,永远不会调用onFling方法。在OSX仿真器上未调用onFling?
我可以使它在windows下工作,但不能在osx上工作。
我用出色的代码从这个帖子: Fling gesture detection on grid layout
这是代码:
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
gestureDetector = new GestureDetector(new MyGestureDetector());
}
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
gestureDetector.onTouchEvent(event);
return false;
}
protected void addFlingSupportToView(int view) {
// TODO Auto-generated method stub
View v = (View) findViewById(view);
v.setOnTouchListener(this);
}
class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
// right to left swipe
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
// Log.i("vampidroid", CryptDetails.this.toString());
finish();
}
} catch (Exception e) {
// nothing
}
return false;
}
}
的问题是,虽然OnTouch被调用时,OnFling事件不会被调用!
我在窗户上玩这个代码,它工作正常。当我更改为osx并尝试一下时,它不起作用。
在设备上,代码按预期工作。
你知道这可能是什么吗?它只与osx有关吗?
我没有在网上找到任何东西,所以我想也许这只是与我或没有人检查。
在此先感谢。
由于输入的处理方式相同,听起来很奇怪。 – Rob 2012-11-03 16:39:21