我在这里发疯了,试图理解为什么我对此一无所知,为什么它不起作用。
我正在使用onFling执行一些操作。工作得很完美。但我想添加一个onlongpress,它将打开一个上下文菜单。onlongpress敬酒词也非常有效。但是当我尝试做一个registerForContextMenu时,问题就来了。如果我给出了我的线性布局,或者我在视图中的任何元素,onlongpress会使上下文菜单显示出来,但我的onfling (根本)不再起作用。
所以我试着只按registerForContextMenu,然后取消注册上下文菜单(是的,这个菜单存在,是的,我也不知道它会这样工作:o),但这不起作用。
那么,你知道为什么"registerForContextMenu“会让浮力停止吗?
如果你需要部分代码,请告诉我。
关于H
编辑;
在我的oncreate中,我调用: registerForContextMenu(ivMain);//这是一个图像视图
gDetect =新的GestureDetector(this,new GestureListener());
我的手势监听器:
public class GestureListener extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onDown(MotionEvent e) {
return true;
}
@Override
public void onLongPress(MotionEvent e) {
super.onLongPress(e);
openContextMenu(ivMain);//my imageview i used registerForContextMenu
}
@Override
public boolean onFling(MotionEvent event1, MotionEvent event2, float velocityX, float velocityY) {
// calculate the change in X position within the fling gesture
float horizontalDiff = event2.getX() - event1.getX();
// calculate the change in Y position within the fling gesture
float verticalDiff = event2.getY() - event1.getY();
float absHDiff = Math.abs(horizontalDiff);
float absVDiff = Math.abs(verticalDiff);
float absVelocityX = Math.abs(velocityX);
// float absVelocityY = Math.abs(velocityY);
if (absHDiff > absVDiff && absHDiff > flingMin && absVelocityX > velocityMin) {
// move forward or backward
if (horizontalDiff < 0) {
stuff();
return true;
}
} else {
otherstuff();
return true;
}
}
}
return false;
}
}发布于 2014-08-21 05:18:43
正如pskink所建议的,我需要移除activity的ontouch覆盖,并将onclicklistener添加到我的视图中,并从那里调用我的手势检测器。
ivMain.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
gDetect.onTouchEvent(event);
//return super.onTouchEvent(event);
return true;
}
});非常感谢pskink。
https://stackoverflow.com/questions/25413559
复制相似问题