简体   繁体   English

MotionEvent.Action_UP失败

[英]MotionEvent.Action_UP fails

I am writing a simple code on ontouchevent..the code is 我在ontouchevent上编写了一个简单的代码。

class MyTouchListener implements View.OnTouchListener{

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub

            if(event.getAction()==MotionEvent.ACTION_DOWN)
            {    Log.i(TAG, "^^^^^^^^^^^ACTION DOWN^^^^^^^^^^^^");
            }

            else if(event.getAction()==MotionEvent.ACTION_UP)
            {
                 Log.i(TAG, "^^^^^^^^^^^ACTION UP^^^^^^^^^^^^");
            }
}

while i pressed the screen it prints ^^^^^ACTION DOWN^^^^^ But when I released the screen it does not print ^^^^^^ACTION UP^^^^^^.... 当我按下屏幕时它会打印^^^^^动作向下^^^^^^但是当我释放屏幕时它不会打印^^^^^^^动作向上^^^^^^^ ....

means MotionEvent.ACTION_UP fails..why this is so?? 表示MotionEvent.ACTION_UP失败。为什么会这样?

Try with MotionEvent.ACTION_CANCEL 尝试使用MotionEvent.ACTION_CANCEL

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

        if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                setColorFilter(Color.argb(155, 185, 185, 185));
        }
        else if (motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL) {
                setColorFilter(Color.argb(0, 185, 185, 185));

        }
        return false;
    }

or add a log in your ontouch method Log.d("tag", "motionEvent=" + motionEvent); 或在ontouch方法Log.d(“ tag”,“ motionEvent =” + motionEvent);中添加日志。

well ACTION_DOWN is happening just once after that action move should be happening and in the and action up... 动作动作应该发生一次之后,ACTION_DOWN就会发生一次,并且在and动作向上...

but there is one problem , for example if you have a touchable area of 48dip x 48dip and if you touch that area and move you finger away (while dragging) I mean you press and you drag you finger away from the touchable area than action up will not happen !!! 但是有一个问题,例如,如果您有一个48dip x 48dip的可触摸区域,并且如果您触摸该区域并将手指移开(拖动时),我的意思是您按了并且将手指从该可触摸区域拖开而不是向上移动不会发生 !!!

Action up will happen only in case when you take your finer of the screen but you are still in the touchable area. 仅当您精简屏幕但仍在可触摸区域时,才会采取行动。 I hope you understand me what I am trying to say. 我希望你能理解我的意思。

if you want mouse up to happen that touch the touchable area do not drag you finger away and take you finger away from the screen, you know just like taping then the up event will happen 如果您希望鼠标向上触摸以触摸可触摸区域,而不会将手指拖离屏幕并使手指离开屏幕,则您知道就像点击一样,就会发生向上事件

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

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