문제

The user will touch a image and it is important that if he left his finger up in that image or not

i tried with writing a onTouchListner() and after that using swich case but i don't know how to continue

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;
            }

        });

thank's in advance

도움이 되었습니까?

해결책

I found my answer through this link but i change it to this:

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;
}

다른 팁

Don't forgot MotionEvent.ACTION_CANCEL

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top