【发布时间】:2011-05-28 15:29:51
【问题描述】:
我希望一个 android 按钮在用户拖动它并在其上释放手指时触发,除了标准激活(如果单击并释放它)。
我尝试使用 ACTION_MOVE MotionEvent,但此事件仅在 ACTION_DOWN 和 ACTION_UP 事件之间触发。我也认为 ACTION_OUTSIDE 可能是一个解决方案。有没有办法做到这一点?
这是我的代码,去掉了所采取的操作(b 是一个按钮):
b.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction()== MotionEvent.ACTION_DOWN){
//Tiggers correctly
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
//Triggers correctly between events, but not when the finger is dragged ontop outside of the element
} else if (event.getAction() == MotionEvent.ACTION_OUTSIDE){
//Can't get this to trigger in any case but I think it might be the solution
} else if (event.getAction() == MotionEvent.ACTION_UP){
//Triggers correctly
}
}
return false;
}
});
【问题讨论】:
标签: android