简体   繁体   English

MotionEvent.ACTION_CANCEL阻止我的按钮上的后续ACTION_UP

[英]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). 它是一个相当大的按钮,当我胖手指时,我得到一个ACTION_CANCEL运动事件而不是ACTION_DOWN(它用指尖完美地工作)。 This prevents it from registering the subsequent ACTION_UP (I assume the view's parent is taking over). 这可以防止它注册后续的ACTION_UP(我假设视图的父节点正在接管)。 I tried using the requestDisallowInterceptTouchEvent() method on the parent, to no avail. 我尝试在父级上使用requestDisallowInterceptTouchEvent()方法,但无济于事。

Here is my onTouch implementation: 这是我的onTouch实现:

    @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. 按下按钮时,我启动AsyncTask,背景根据该任务的进度而变化。 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. 编辑:我一直沿着View层次结构走到ViewRootImpl,但仍然没有运气调用requestDisallowInterceptTouchEvent()。 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 08-26 11:06:15.287:D / ViewRootImpl(5428):[ViewRootImpl]动作取消 - 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. 很明显,似乎该动作要么在它进入ViewRootImpl之前被取消,要么就在之后被取消。 How is this even possible? 这怎么可能呢?

Update: Still no progress on this... anyone? 更新:这个没有进展......任何人?

Update 2: I think this may be a device dependent issue. 更新2:我认为这可能是设备相关的问题。 I'm using a Galaxy S4 我正在使用Galaxy S4

This seems to be a device dependent issue with the Galaxy S4, I was unable to reproduce it on other devices. 这似乎与Galaxy S4的设备相关问题,我无法在其他设备上重现它。 I ended up just cancelling the task if a MotionEvent.ACTION_CANCEL was picked up. 如果拾取了MotionEvent.ACTION_CANCEL ,我最终只是取消了该任务。

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

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