简体   繁体   中英

MotionEvent.ACTION_CANCEL is blocking subsequent ACTION_UP on my button

I have a button on one of my fragments, that sits inside a relative layout. It's a rather large button, and when I fat finger it I get a ACTION_CANCEL motion event rather than ACTION_DOWN (it works perfectly fine with finger tips). This prevents it from registering the subsequent ACTION_UP (I assume the view's parent is taking over). I tried using the requestDisallowInterceptTouchEvent() method on the parent, to no avail.

Here is my onTouch implementation:

    @Override
    public boolean onTouch(View view, MotionEvent event) {

    //debugging
    Log.v("TOUCH EVENT", event.toString());


    int action = event.getAction(); 





    if (action == MotionEvent.ACTION_DOWN) {
        mButton.getParent().requestDisallowInterceptTouchEvent(true);
        //Do stuff...

        return true;

    } else if (action == MotionEvent.ACTION_UP) {

        //Do other stuff...

        return true;

    } else if (action == MotionEvent.ACTION_CANCEL){

        return false;
        //Toast.makeText(context, "Your thumb is too fat.", Toast.LENGTH_SHORT).show();
    }


    return false;
}

Note that the button also uses custom background resources. I start an AsyncTask when the button is pressed and the background changes based on the progress of that task. I'm not sure if that has anything to do with the problem or not.

EDIT: I walked all the way up the View hierarchy to ViewRootImpl, and still no luck in calling requestDisallowInterceptTouchEvent() on it. Weird thing is this shows in the log when my button sticks:

08-26 11:06:15.287: D/ViewRootImpl(5428): [ViewRootImpl] action cancel - 1, s:31 s(atmel):-1.0 eccen:1.3333334

So obviously it seems that the action is either being cancelled before it even gets inside the ViewRootImpl or right after. How is this even possible?

Update: Still no progress on this... anyone?

Update 2: I think this may be a device dependent issue. I'm using a Galaxy S4

This seems to be a device dependent issue with the Galaxy S4, I was unable to reproduce it on other devices. I ended up just cancelling the task if a MotionEvent.ACTION_CANCEL was picked up.

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