gpt4 book ai didi

android - ACTION_CANCEL 未触发

转载 作者:搜寻专家 更新时间:2023-11-01 08:55:14 34 4
gpt4 key购买 nike

我实现了一个 customView 以在触摸和松开 View 时添加一点动画。当用户点击这个 View 时,我会启动一个 80 毫秒的小动画来缩小 View 。

当手指向上时,播放相同的动画(反向效果)。视觉效果很好,只要用户不移动手指就可以正常工作。

因此,当手指离开 View 区域时,我无法收到任何对 ACTION_CANCEL 的调用,而在我的情况下,这是播放动画所必需的。

ACTION_UP、ACTION_MOVE 和 ACTION_DOWN 被正确调用,但从不调用 ACTION_CANCEL

这是我的代码:

@Override
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
switch (event.getAction()) {
case MotionEvent.ACTION_CANCEL: {
Animation anim = new ScaleAnimation(0.9f, 1f, 0.9f, 1f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
anim.setDuration(Utils.ANIM_CLICK_LENGHT);
anim.setFillAfter(true);
anim.setFillBefore(true);
startAnimation(anim);
break;
}
case MotionEvent.ACTION_DOWN: {
Animation anim = new ScaleAnimation(1f, 0.9f, 1f, 0.9f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
anim.setDuration(Utils.ANIM_CLICK_LENGHT);
anim.setFillAfter(true);
anim.setFillBefore(true);
startAnimation(anim);
break;
}
case MotionEvent.ACTION_UP: {
Animation anim = new ScaleAnimation(0.9f, 1f, 0.9f, 1f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
anim.setDuration(Utils.ANIM_CLICK_LENGHT);
anim.setFillAfter(true);
anim.setFillBefore(true);
startAnimation(anim);
break;
}
}
return true;
}

最佳答案

检查这个答案:https://stackoverflow.com/a/20160587/1576319

它详细解释了为什么 ACTION_CANCEL 在 API>16 中没有被触发,并提供了一个快速的解决方法。

关于android - ACTION_CANCEL 未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19498773/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com