将双击手势限制为仅双击一次

Limit doubletap gesture to just one double tap

我实现了这个 onDoubleTap 方法,它真的很简单,它只是弹出一张照片,我喜欢的是,如果我执行 doubleTap 它只是一次动画我又做了一次,现在不行了

这是我的代码

@Override
public boolean onDoubleTap(MotionEvent motionEvent) {
    animateHeart(myImageView);
    return false;
}

public void animateHeart(final ImageView view) {
    ScaleAnimation scaleAnimation = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f,
    Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
            prepareAnimation(scaleAnimation);

    AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 3.0f);
    prepareAnimation(alphaAnimation);

    AnimationSet animation = new AnimationSet(true);
    animation.addAnimation(alphaAnimation);
    animation.addAnimation(scaleAnimation);
    animation.setDuration(400);
    animation.setFillAfter(true);

    view.startAnimation(animation);    
}

private Animation prepareAnimation(Animation animation){
    animation.setRepeatCount(1);
    animation.setRepeatMode(Animation.REVERSE);
    return animation;
}

谢谢

首先需要returntrue如果事件被消费了。那你为什么没有一个flag来检查你是否已经处理过呢?

private boolean isConsumed;

@Override
public boolean onDoubleTap(MotionEvent motionEvent) {
    if (!isConsumed) {
        animateHeart(myImageView);
        isConsumed = true;
    }
    return true;
}