Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

action_up doesn't call after action_move

I have an animation that makes a button press down on touch. I want it to be able to stay pressed down, while the user scrolls the screen. To do this, I made an animation that basically just keeps the image in the same state to call in the ACTION_MOVE. My problem is that when I release the button, the ACTION_UP isn't being called which is what triggers the animation to bring the button back to it's full size and no longer looking pressed. I have the entire relative layout inside a ScrollView. I still don't understand fully what's happening, but it appears that the ScrollView may be "taking over" the onTouch events. Here is my code for the onTouchListener.

s104.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                clearAnim();
                s104.setAnimation(animPressed);
                s104.startAnimation(animPressed);
                return true;
            case MotionEvent.ACTION_MOVE:
                s104.setAnimation(animDrag);
                s104.startAnimation(animDrag);
                return true;
            case MotionEvent.ACTION_UP:

                s104.setAnimation(animReleased);
                s104.startAnimation(animReleased);

                return true;
            }
            return false;
        }
    });

I can't figure out why the ACTION_UP isn't being called. Any help would be greatly appreciated.

like image 835
Trent Avatar asked Oct 15 '13 04:10

Trent


1 Answers

I still don't understand fully what's happening, but it appears that the ScrollView may be "taking over" the onTouch events.

That is correct. What you are experiencing is the ScrollView "taking over" the MotionEvent. You can capture this event in your OnTouchListener - add a case for MotionEvent.ACTION_CANCEL. In there you can determine the outcome if the user has pressed the View (ACTION_DOWN) and subsequently scrolled down.

like image 117
Toshe Avatar answered Oct 10 '22 15:10

Toshe