Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.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/8/xslt/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
Java 检查MotionEvent.ACTION\u UP是否不在imageview中_Java_Android_Ontouchlistener_Motionevent - Fatal编程技术网

Java 检查MotionEvent.ACTION\u UP是否不在imageview中

Java 检查MotionEvent.ACTION\u UP是否不在imageview中,java,android,ontouchlistener,motionevent,Java,Android,Ontouchlistener,Motionevent,用户将触摸图像,重要的是他是否将手指放在该图像中 我试着写一个onTouchListner(),然后用swich case,但我不知道如何继续 image.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent event) { switch (event.getActio

用户将触摸图像,重要的是他是否将手指放在该图像中

我试着写一个
onTouchListner()
,然后用
swich case
,但我不知道如何继续

image.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View arg0, MotionEvent event) {

                switch (event.getAction()) {
                    case MotionEvent.ACTION_UP:
                        break;
                    case MotionEvent.ACTION_DOWN:
                        break;
                    case MotionEvent.ACTION_MOVE:
                        break;
                }

                return true;
            }

        });

提前感谢

我通过此找到了答案,但我将其更改为:

private Rect rect;    // Variable rect to hold the bounds of the view

public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction()) {
        case MotionEvent.ACTION_UP:
            if (!rect.contains(v.getLeft() + (int) event.getX(), v.getTop() + (int) event.getY())) {
                // User moved outside bounds
            }
            break;
        case MotionEvent.ACTION_DOWN:
            rect = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
            break;
    }
    return false;
}

别忘了MotionEvent.ACTION\u CANCEL

你有没有尝试过外面的
ACTION\u
?你解决了我的问题!!谢谢如果你想得到另一个答案,请看我的最后一个问题!没有人能回答它,而你用“!rect.contains(…);”解决了它