将双重手势限制为只需一次双击(Limit doubletap gesture to just one double tap)

编程入门 行业动态 更新时间:2024-10-28 14:33:11
将双重手势限制为只需一次双击(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; }

更多推荐

本文发布于:2023-08-01 16:56:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1361255.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:只需   双击   手势   Limit   tap

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!