2011-10-20 2 views

답변

3

OnTouch

당신은 당신이 드래그를 인식 할 볼에 대한 어떤 OnTouchListener를 구현해야합니다.

그러면 onTouchListener에서 X 및 Y 좌표를 표시해야합니다. MotionEvent.getRawX() 및 MotionEvent.getRawY()를 통해 이들을 가져올 수 있다고 생각합니다.

끌기가 발생하는 경우 MotionEvent.getAction() 메서드를 사용하여 찾을 수 있습니다. 상수는 MotionEvent.ACTION_MOVE라고 생각합니다. 여기에 몇 가지 사이비 코드는 다음과 같습니다

public void onCreate(Bundle savedInstanceState) 
{ 
    //other code 

    View onTouchView = findViewById(R.id.whatever_id); 
    onTouchView.setOnTouchListener(this); 
} 

public boolean onTouch(View view, MotionEvent event) 
{ 
    if(event.getAction() == MotionEvent.ACTION_MOVE) 
    { 
     float x = event.getRawX(); 
     float y = event.getRawY(); 
     // Code to display x and y go here 
    } 
} 
+0

확인 onTouch 방법을 구현

public class XYZ extends Activity implements OnTouchListener 

OnTouchListener 인터페이스는에서 onCreate 방법에 리스너를 등록하세요! 좋은 대답! – Mateus

관련 문제