2013-10-21 18 views

回答

2

關注這個代碼觸摸事件用於拖動

@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 

    } 

而對於拉線此鏈接 How to draw a line in android

+0

對於這個例子中我需要延長活動或查看? – Uday

+0

您需要擴展Activity並實現OnTouchlistner – Indra

相關問題