Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-防止触摸事件中的滑动/拖动_Android_User Input_Touch Event - Fatal编程技术网

Android-防止触摸事件中的滑动/拖动

Android-防止触摸事件中的滑动/拖动,android,user-input,touch-event,Android,User Input,Touch Event,我正在使用下面的代码来检测屏幕上的点击,但是我注意到它会对滑动做出响应,并多次激活事件处理程序中的代码,如何停止?谢谢 @Override public boolean onTouchEvent(MotionEvent event) { int x = (int)event.getX(); if (x < viewWidth/2) { xDir -= 10; } else { xDir += 10;

我正在使用下面的代码来检测屏幕上的点击,但是我注意到它会对滑动做出响应,并多次激活事件处理程序中的代码,如何停止?谢谢

    @Override
public boolean onTouchEvent(MotionEvent event) {
    int x = (int)event.getX();
    if (x < viewWidth/2)
    {
        xDir -= 10;

    }

    else
    {
        xDir += 10;
    }
    return true;
}
@覆盖
公共布尔onTouchEvent(运动事件){
int x=(int)event.getX();
如果(x
u应该使用如下内容:

            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    int x = (int)event.getX();
                    if (x < viewWidth/2) {
                       xDir -= 10;
                    }else  {
                       xDir += 10;
                    }
                } 
            }
public boolean onTouch(视图v,运动事件){
if(event.getAction()==MotionEvent.ACTION\u UP){
int x=(int)event.getX();
如果(x

注意:您可以使用其他MotionEvent标志,如ACTION\u DOWN…

谢谢您的帮助,但我已经阅读了它,因此我使用了我的初始代码,但是我仍然不知道哪里出了问题。