简体   繁体   English

不调用MotionEvent.ACTION_UP

[英]MotionEvent.ACTION_UP is not called

i have a problem with an OnSwipeImageListener (implements OnTouchListener ). 我对OnSwipeImageListener (实现OnTouchListener )有问题。 I use the OnSwipeImageListener in two activities. 我在两个活动中使用OnSwipeImageListener
On the one activitiy on the ImageView is the OnTouchListener and an OnClickListener and on the other activity on the ImageView is only the OnTouchListener . ImageView上的一个活动是OnTouchListenerOnClickListener ,在ImageView上的另一活动仅是OnTouchListener
If i change return v. onTouchEvent(event) to true under the MotionEvent.ACTION_DOWN then the OnClickListener on the first activity doesn't work and in this way the Swipe of ImageView on the second activity doesn't work. 如果我改变返回诉onTouchEvent(event)trueMotionEvent.ACTION_DOWN那么OnClickListener上的第一个活动不能正常工作,并以这种方式轻扫ImageView第二活动不起作用。 I debugged some times and see that MotionEvent.ACTION_UP is never called. 我进行了一些调试,发现从未调用MotionEvent.ACTION_UP

public boolean onTouch(View v, MotionEvent event) {

    switch(event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        dX = event.getX();
        dY = event.getY();
        return v.onTouchEvent(event);
    case MotionEvent.ACTION_UP:
        uX = event.getX();
        uY = event.getY();

        float deltaX = dX - uX;
        float deltaY = dY - uY;

        // horizontal
        if(Math.abs(deltaX) > MIN_DISTANCE) {

            //Left to right
            if(deltaX < 0) {
                this.onLeftToRight();
                return v.onTouchEvent(event);
            } else if (deltaX > 0) {
                this.onRightToLeft();
                return v.onTouchEvent(event);
            }
            else {
                //Swipe too short
                return v.onTouchEvent(event);
            }
        }

        // vertical
        if (Math.abs(deltaY) > MIN_DISTANCE) {

            if(deltaY < 0) {
                this.onTopToBottom();
                return v.onTouchEvent(event);
            } else if (deltaY > 0) {
                this.onBottomToTop();
                return v.onTouchEvent(event);
            }
            else {
                //Swipe too short
                return v.onTouchEvent(event);
            }
        }
    }
    return v.onTouchEvent(event);
}

If you want to get the ACTION_UP, you should hijack the ACTION_DOWN. 如果要获取ACTION_UP,则应劫持ACTION_DOWN。

Instead of returning " v.onTouchEvent(event) ", return " true " when you are just handling the ACTION_DOWN. 当您仅处理ACTION_DOWN时,不返回“ v.onTouchEvent(event) ”,而返回“ true ”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 检查MotionEvent.ACTION_UP是否超出imageview - Check if MotionEvent.ACTION_UP is out of the imageview 没有显示MotionEvent.ACTION_UP或MotionEvent.ACTION_CANCEL - not showing MotionEvent.ACTION_UP or MotionEvent.ACTION_CANCEL Android MotionEvent.ACTION_MOVE和MotionEvent.ACTION_UP - Android MotionEvent.ACTION_MOVE and MotionEvent.ACTION_UP 使用OnTouchListener,MotionEvent.ACTION_UP时,应用程序意外停止 - App stops unexpectedly when using OnTouchListener, MotionEvent.ACTION_UP 我想在一个活动中调用MotionEvent.ACTION_DOWN,在另一个活动中调用MotionEvent.ACTION_UP - i want call MotionEvent.ACTION_DOWN in one activity and MotionEvent.ACTION_UP in another activity 在ACTION_DOWN中启动后,CountDownTimer在MotionEvent.ACTION_UP上未取消 - CountDownTimer not cancelled on MotionEvent.ACTION_UP after starting it in ACTION_DOWN MotionEvent-Java中的action_move(监听action_up) - MotionEvent - action_move (listening for action_up) in java scollview启动时未检测到android.view.MotionEvent.ACTION_UP - android.view.MotionEvent.ACTION_UP not detected when scollview kicks in 第一次恢复后Android onTouchListener Action_Up-MotionEvent延迟 - Android onTouchListener Action_Up-MotionEvent delayed after first resume ImageView MotionEvent如果有两个指针,则停止ACTION_UP - ImageView MotionEvent if two pointer, stop ACTION_UP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM