简体   繁体   English

通过事件时的MotionEvent Action_Up问题

[英]MotionEvent Action_Up issues on passing event

I have a top(transparant) view over my appliction. 我对自己的申请有一个顶视图。
this is supposed to catch a Long press of 5 seconds and open a menu . 长按5秒并打开菜单。 So i implemented an OnTouchListener . 所以我实现了一个OnTouchListener。 like this : 像这样 :

public boolean onTouch(View v, MotionEvent event)
                {       
                        long downtime = 0;
                        long eventt = 0;


                        boolean returnvalue = false; 

                        switch (event.getAction() & MotionEvent.ACTION_MASK) 
                        {

                        case MotionEvent.ACTION_DOWN:
                             eventt = event.getEventTime();                         
                             returnvalue = true; 
                             break;

                        case MotionEvent.ACTION_UP:

                            downtime = event.getDownTime();
                            if (eventt - downtime > 5000)
                            {
                                Main.changePlayerDialog.show();
                                returnvalue = true;
                            }
                            else
                            { 
                                returnvalue = false;
                                //return false;
                            }
                            break;

                        default: 
                                break;
                       }                

                        return returnvalue;

                    }
                });

now , for the 5 second touch and release this works just fine. 现在,对于5秒钟的触摸和释放,效果很好。 however , when its less then 5 ,I return false. 但是,当它小于5时,我返回false。 The MotionEvent however isn't passed down to other views beneath it ! 但是,MotionEvent不会传递到其下的其他视图! so all buttons and such of underlying views are now 'disabled' ... 所以所有按钮以及诸如此类的基础视图现在都被“禁用”了...

If i return false straightaway everything works fine... but then the ACTION_UP doesn't trigger anymore if a underlying button has been triggered. 如果我返回错误的结果,一切都很好...但是,如果已触发基础按钮,则ACTION_UP不会再触发。 (seems logical, event has been handled somewhere else). (似乎合乎逻辑,事件已在其他地方处理)。

how can i fix this ? 我怎样才能解决这个问题 ?

Have you tried returning : 您是否尝试过返回:

return super.onTouch(v, event);

?

--- Edit -编辑

Well, if you do so : 好吧,如果您这样做:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     >

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="coucou"
        android:id="@+id/button" />


    <LinearLayout  android:id="@+id/linear"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
         />

</RelativeLayout>

And add onTouch on linear layout and on click on button, the button will never catch the event... 并在线性布局上添加onTouch并单击按钮,该按钮将永远不会捕获事件...

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

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