MotionEvent.ACTION_CANCEL阻止后续ACTION_UP我的按钮 [英] MotionEvent.ACTION_CANCEL is blocking subsequent ACTION_UP on my button

查看:992
本文介绍了MotionEvent.ACTION_CANCEL阻止后续ACTION_UP我的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的碎片一个按钮,它位于一个相对的布局中。 这是一个相当大的按钮,当我胖手指它,我得到一个ACTION_CANCEL运动事件,而不是ACTION_DOWN(它完美的罚款与指尖)。这$ P $从注册以后ACTION_UP pvents它(我假设视图的父接管)。我试着用requestDisallowInterceptTouchEvent()方法的家长,都无济于事。

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.

下面是我的onTouch实现:

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;
}

请注意,该按键还采用了自定义背景的资源。我开始一个AsyncTask的按钮时,pressed以及基于任务的进度背景的变化。我不知道这有什么的问题或没有。

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.

编辑:我一路走过来查看层次结构ViewRootImpl,并仍在调用requestDisallowInterceptTouchEvent()就可以了没有运气。奇怪的是这表明在日志中时,我的按钮枝:

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:

十一月8日至26号:06:15.287:D / ViewRootImpl(5428):[ViewRootImpl]行动取消 - 1,S:31秒(爱特梅尔): - 1.0加入收藏登录:1.3333334

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

所以,很显然它似乎是采取行动要么被取消之前,甚至得到里面的ViewRootImpl或右后。这怎么可能?

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?

更新2:我觉得这可能是一个与设备相关的问题。我使用的是银河S4

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

推荐答案

这似乎与银河S4设备相关的问题,我无法重现它在其他设备上。我最终只是取消了任务,如果一个 MotionEvent.ACTION_CANCEL 被拾起。

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.

这篇关于MotionEvent.ACTION_CANCEL阻止后续ACTION_UP我的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆