【发布时间】:2015-02-16 00:43:18
【问题描述】:
这是我的 onTouchEvent(MotionEvent 事件)的代码:
@Override
public boolean onTouchEvent(MotionEvent event){
int action = event.getAction();
int x = Math.round(event.getX());
int y = Math.round(event.getY());
//play is an imageView
int viewLeft = play.getLeft();
int viewRight = play.getRight();
int viewTop = play.getTop();
int viewBottom = play.getBottom();
boolean onPoint = false;
switch (action) {
case MotionEvent.ACTION_DOWN:
//Checks if the touched area falls within the imageView play
if ((x >= viewLeft && x <= viewRight) && (y >= viewTop && y <= viewBottom)) {
onPoint = true;
play.setImageResource(R.drawable.playyellow);
}
case MotionEvent.ACTION_UP:
//if the finger is lifed on the imageView, the intent is called
play.setImageResource(R.drawable.play1);
if (onPoint) {
if ((x >= viewLeft && x <= viewRight) && (y >= viewTop && y <= viewBottom)) {
Intent i = new Intent(this, InGame.class);
startActivity(i);
}
}
}
return true;
}
这里的问题是 ACTION_UP 总是被调用,无论我是否真的将手指从屏幕上抬起。我在调试模式下运行它,同时在案例 MotionEvent.ACTION_UP 上放置一个断点,当我按下(并且没有释放)时,它被调用了。有人可以解释为什么会这样吗?
【问题讨论】:
标签: android motionevent