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

时间:2017-05-10 20:59:51

标签: android animation gesture

我已经实现了这个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;
}

由于

1 个答案:

答案 0 :(得分:0)

首先,如果事件被消耗,您需要返回true。那么,为什么你没有标志来检查你是否已经处理过它?

private boolean isConsumed;

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