Pergunta

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

Foi útil?

Solução

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

Outras dicas

Don't forgot MotionEvent.ACTION_CANCEL

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top