Concept
The touch screen (touchscreen) and the Rolling ball (trackball) are the main input devices in addition to the keyboard in Android.
Both events can be used to receive their messages using motion events (motionevent).
Just look at the code.
Packagecom.example.motion;Importandroid.support.v7.app.ActionBarActivity;ImportAndroid.os.Bundle;Importandroid.view.MotionEvent;ImportAndroid.widget.TextView; Public classMainactivityextendsactionbaractivity {TextView maction=NULL; TextView mpostion=NULL; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Maction=(TextView) Findviewbyid (r.id.action); Mpostion=(TextView) Findviewbyid (r.id.position); } Public Booleanontouchevent (Motionevent event) {intAction =event.getaction (); floatx =Event.getx (); floaty =event.gety (); Maction.settext ("Action:" +action); Mpostion.settext ("POS: \nx:" +x + "\ny:" +y); return true; }}
Take a look at the results.
The action represents the status of the currently pressed screen:
Motionevent.action_down is 0
MOTIONEVENT.ACTION_UP is 1
Motionevent.action_move is 2
In addition, X, Y represents the current pressed horizontal ordinate.
"Android Development Learning note", "Tenth lesson"--touch screen