1
回答
eclipse的android程序一运行就进入调试,为什么
package cn.com.example.touch;


import android.os.Bundle;
import android.app.Activity;
import android.widget.*;
import android.view.MotionEvent;


public class MainActivity extends Activity {
      private TextView text2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
text2=(TextView)findViewById(R.id.text2);
setContentView(R.layout.activity_main);
}
    
@Override
public boolean onTouchEvent(MotionEvent event){
int action=event.getAction();
switch(action){
case(MotionEvent.ACTION_DOWN):
Display("ACTION_DOWN",event);
   break;
   
case(MotionEvent.ACTION_UP):
Display("ACTION_UP",event);
   break;
   
case(MotionEvent.ACTION_MOVE):
Display("ACTION_MOVE",event);
}
 return super.onTouchEvent(event);
}
public void Display(String eventType,MotionEvent event){
            int x=(int)event.getX();
            int y=(int)event.getY();
            
            float pressure=event.getPressure();
            float size=event.getSize();
            
            String msg="";
            msg+="事件类型:"+eventType+"\n";
            msg+="坐标(x,y):"+String.valueOf(x)+","+String.valueOf(y)+"\n";
            msg+="触点压力:"+String.valueOf(pressure)+"\n";
            msg+="触点尺寸:"+String.valueOf(size)+"\n";
            text2.setText(msg);


}
}
举报
桀聪
发帖于4年前 1回/1K+阅
顶部