简体   繁体   中英

MotionEvent.ACTION_UP is not called

i have a problem with an OnSwipeImageListener (implements OnTouchListener ). I use the OnSwipeImageListener in two activities.
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 .
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. I debugged some times and see that MotionEvent.ACTION_UP is never called.

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.

Instead of returning " v.onTouchEvent(event) ", return " true " when you are just handling the ACTION_DOWN.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM