2011-02-24 10 views

Respuesta

10

Puede reemplazar el método onTouchEvent en su View:

@Override 
public boolean onTouchEvent (MotionEvent event) { 

    if (event.getAction() == MotionEvent.ACTION_DOWN) { 

    start_x = event.getX(); 
    start_y = event.getY();  

    } else if (event.getAction() == MotionEvent.ACTION_MOVE) { 

    //create the line from start_x and start_y to the current location 
    //don't forget to invalidate the View otherwise your line won't get redrawn 

    } else if (event.getAction() == MotionEvent.ACTION_UP) { 

    //might not need anything here 

    } 
    return true; 
} 

estoy asumiendo que usted desea dibujar una línea recta desde el inicio del arrastre para el punto final y no quieren "Doodle" , pero es bastante simple modificar este código para manejar cualquiera.

Cuestiones relacionadas