简体   繁体   English

Android-触摸屏幕时执行某些操作

[英]Android - Do something while touching the screen

There is an extended SurficeView class that I want that while the user is touching the screen (like onKeyDown) it does something. 我想要一个扩展的SurficeView类,当用户触摸屏幕时(例如onKeyDown),它可以执行某些操作。

Like this: 像这样:

@Override
    public boolean onTouchEvent(MotionEvent event) {
        Log.e("Touching", "Touching the Screen");
        return true;
    }

While the user is touching the screen I want my LogCat to be spammed (just testing) 'til I'm not touching it but it only shows the message twice: when I touch and when I release. 当用户触摸屏幕时,我希望向LogCat发送垃圾邮件(只是进行测试),直到我没有触摸它,它只显示两次消息:当我触摸和释放时。

Here is Different Behavour of OnTouch Listener 这是OnTouch监听器的不同行为

setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                Log.d(TAG, "mode=DRAG");
                switch (event.getAction() & MotionEvent.ACTION_MASK) {
                case MotionEvent.ACTION_DOWN:
                    Log.i("Tag", "1");

                    break;
                case MotionEvent.ACTION_POINTER_DOWN:
                    Log.i("Tag", "2");

                    break;// return  
                case MotionEvent.ACTION_UP:
                    Log.i("Tag", "3");

                case MotionEvent.ACTION_POINTER_UP:
                    Log.i("Tag", "4");


                    break;
                case MotionEvent.ACTION_MOVE:
                    Log.i("Tag", "5");
                    break;
                }
                return true;
            }
        });

write Log in one of below actions like: 写入以下操作之一,例如:

@Override
public boolean onTouchEvent(MotionEvent event) {
   if(event.getAction==MotionEvent.ACTION_DOWN){
    Log.e("Touching", "Touching the Screen");
  }
    else if(event.getAction==MotionEvent.ACTION_UP){
    Log.e("Touching up", "Touching the Screen up");}
    return true;
}

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

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