在我们的Android程序中,我们无法在正确的时间获取方法。我们有一个ontouchlistener,我们试图让它在发布时调用,这意味着其他功能将继续进行。但是,“ontouch”中的所有内容都会同时发生。在其他方法完成后,我们如何才能调用其他方法?
@Override
public boolean onTouch(View v, MotionEvent event) {
Tile touchedTile = (Tile) v;
if (touchedTile.isEmpty() || !touchedTile.isInRowOrColumnOf(emptyTile)) {
return false;
}
else {
mediaPlayer.start();
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
movedTile = touchedTile;
currentMovement = getTilesBetweenEmptyTileAndTile(movedTile);
//movedTile.numberOfMoves = 0;
}
else if (event.getActionMasked() == MotionEvent.ACTION_MOVE) {
if (lastDragPoint != null) {
followFinger(event);
}
lastDragPoint = new PointF(event.getRawX(), event.getRawY());
}
else if (event.getActionMasked() == MotionEvent.ACTION_UP) {
currentMovement = getTilesBetweenEmptyTileAndTile(movedTile);
if (lastDragMovedAtLeastHalfway() || isClicked()) {
animateTilesToEmptySpace();
checkMatch();
}
else {
animateTilesBackToOrigin();
}
currentMovement = null;
lastDragPoint = null;
movedTile = null;
}
return true;
}
}
答案 0 :(得分:0)
如果您正在寻找复杂的倾听者,那么您应该查看MotionEvent,因此对于MotionEvent.ACTION_UP
,该文档说:
...按下的手势已经完成,动作包含最终发布位置以及自上次下移或移动事件以来的任何中间点....
有很多关于它的信息。
答案 1 :(得分:0)
编辑:看起来你正试图用一个空单元格制作一个拼图游戏。
考虑到您必须使用动画对象,您还必须在动画更新侦听器上注册。你不应该在其中放入checkMatch()方法,以便在动画结束时调用它,因为只有在用户移动切片后才会发生匹配吗?