问题描述
我在我的MapActivity实现的OnTouchListener,当然,我不得不重写onTouch()方法。
我想,当我点击地图上它只是火 - 否则我甚至不能移动地图
下面是我的onTouch方式:
@覆盖
公共布尔onTouch(视图V,MotionEvent五){ 如果(e.getAction()== MotionEvent.ACTION_DOWN){ //一些行动...... }
返回true;
}
使用:
e.getAction()== MotionEvent.ACTION_UP
和
e.getAction()== MotionEvent.ACTION_MOVE
如果有和ACTION_UP事件后ACTION_DOWN,之间并没有ACTION_MOVE,它的一个水龙头
更新:
私人INT mLastMotionEventAction = MotionEvent.ACTION_UP;@覆盖
公共布尔onTouch(视图V,MotionEvent五){ 如果(e.getAction()== MotionEvent.ACTION_DOWN){
//有人下行动... }否则如果(e.getAction()== MotionEvent.ACTION_MOVE){ //有所动作动作... }否则如果(e.getAction()== MotionEvent.ACTION_UP){
如果(mLastMotionEventAction == MotionEvent.ACTION_DOWN){ //一些TAP行动... }
}
mLastMotionEventAction = e.getAction();
返回true;
}
另一种选择(对于敏感设备):
私人长期mLastDownEventTime = 0; @覆盖
公共布尔onTouch(视图V,MotionEvent五){ 如果(e.getAction()== MotionEvent.ACTION_DOWN){
mLastDownEventTime = System.currentTimeMillis的(); //有人下行动... }否则如果(e.getAction()== MotionEvent.ACTION_MOVE){ //有所动作动作... }否则如果(e.getAction()== MotionEvent.ACTION_UP){
如果(System.currentTimeMillis的() - mLastDownEventTime< 500){ //一些TAP行动... }
} 返回true;
}
这将触发动作水龙头只有200毫秒以内以来下跌了preSS通过。当然,你可以改变的最佳UX时机。
I've implemented an OnTouchListener in my MapActivity and of course I had to override the onTouch() method.
I want it to fire only when I tap on the map - otherwise I can't even move the map.
Here's my onTouch method:
@Override
public boolean onTouch(View v, MotionEvent e) {
if (e.getAction() == MotionEvent.ACTION_DOWN) {
// SOME ACTIONS ...
}
return true;
}
use:
e.getAction() == MotionEvent.ACTION_UP
and:
e.getAction() == MotionEvent.ACTION_MOVE
if there was and ACTION_UP event after and ACTION_DOWN, and no ACTION_MOVE between, its a tap
UPDATED:
private int mLastMotionEventAction = MotionEvent.ACTION_UP;
@Override
public boolean onTouch(View v, MotionEvent e) {
if (e.getAction() == MotionEvent.ACTION_DOWN) {
// SOME DOWN ACTIONS ...
} else if (e.getAction() == MotionEvent.ACTION_MOVE) {
// SOME MOVE ACTIONS ...
} else if (e.getAction() == MotionEvent.ACTION_UP) {
if (mLastMotionEventAction == MotionEvent.ACTION_DOWN){
// SOME TAP ACTIONS ...
}
}
mLastMotionEventAction = e.getAction();
return true;
}
Another option (for sensitive devices):
private long mLastDownEventTime = 0;
@Override
public boolean onTouch(View v, MotionEvent e) {
if (e.getAction() == MotionEvent.ACTION_DOWN) {
mLastDownEventTime = System.currentTimeMillis();
// SOME DOWN ACTIONS ...
} else if (e.getAction() == MotionEvent.ACTION_MOVE) {
// SOME MOVE ACTIONS ...
} else if (e.getAction() == MotionEvent.ACTION_UP) {
if (System.currentTimeMillis() - mLastDownEventTime < 500){
// SOME TAP ACTIONS ...
}
}
return true;
}
This will trigger tap action only if 200ms or less have passed since last down press. Of course, you can change the timing for best UX.
这篇关于如何使onTouch就像在的onTap Android的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!