onTouchEvent方法記錄觸屏動作和觸屏位置。
下面我們來看一下代碼。
代碼其實很簡單,就是兩個TextView控件,第一個記錄觸屏事件,第二個記錄觸屏位置。
然後設置一個外部類
public boolean onTouchEvent(MotionEvent event) {
int Action=event.getAction();
float X=event.getX();
float Y=event.getY();
Log.v(TAG, "Action="+Action);
Log.v(TAG, "("+X+","+Y+")");
mAction.setText("Action="+Action);
mpostion.setText("Position=("+X+","+Y+")");
return true;
}
然後運行程序就可以了。其中的Log在前面的介紹中有提到。