将双重手势限制为只需一次双击(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; }谢谢
I have this onDoubleTap method implemented, it is really simple, it just pops up a photo, what I like is that if I do the doubleTap it just animate it one time and when I do it again it dosn't do it anymore
Here is my code
@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; }Thanks
最满意答案
首先,如果事件已消耗,则需要返回true 。 那么,为什么你没有一个国旗来检查你是否已经处理了它?
private boolean isConsumed; @Override public boolean onDoubleTap(MotionEvent motionEvent) { if (!isConsumed) { animateHeart(myImageView); isConsumed = true; } return true; }First of all, you need to return true if the event is consumed. Then, why don't you have a flag to check if you already handled it?
private boolean isConsumed; @Override public boolean onDoubleTap(MotionEvent motionEvent) { if (!isConsumed) { animateHeart(myImageView); isConsumed = true; } return true; }更多推荐
发布评论