OnTouch events in Android events:
How to Implement:
1 monitoring
2 Back Adjustment
1 Monitoring:
Package Com.example.conflicttest;import Android.os.bundle;import Android.app.activity;import android.util.Log; Import Android.view.menu;import Android.view.motionevent;import Android.view.view;import Android.view.view.ontouchlistener;import Android.widget.imageview;import Android.widget.linearlayout;public Class Mainactivity extends Activity implements Ontouchlistener {private linearlayout sublayout;private ImageView imgview;/* ( Non-javadoc) * @see android.app.activity#oncreate (android.os.Bundle) */@Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); subLayout = ( LinearLayout) Findviewbyid (r.id.sublayout); Imgview = (ImageView) Findviewbyid (R.id.imgview);// Sublayout.setontouchlistener (this);/** * Event Monitoring the first scenario: Set up listening! * */imgview.setontouchlistener (this);} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it is PR Esent.getmenuinflater (). Inflate (r.mEnu.main, menu); return true;} /** * Return False event return call, passed to parent class! * */@Overridepublic Boolean OnTouch (View V, motionevent event) {//TODO auto-generated method Stubint action = Event.geta Ction (); Float rawx = event.getrawx (); Float Rawy = Event.getrawy (); float x = Event.getx (); Float y = event.gety (); LOG.D ("Lvoe", "----on touch:" + V + "raw[" + rawx + "," + Rawy + "],xy[" + x+ "," + y + "]"); return true;}
2 Callback ":
Package Com.example.conflicttest;import Android.content.context;import Android.util.attributeset;import Android.util.log;import android.view.motionevent;import android.widget.linearlayout;/** * @author Hades * * */public Class Customlinerlayout extends LinearLayout {public customlinerlayout (context context) {super (context);//TODO Auto-generated Constructor Stub}public customlinerlayout (context context, AttributeSet Attrs) {Super (context, attrs); /TODO auto-generated Constructor Stub}public customlinerlayout (context context, AttributeSet attrs, int defstyle) {Super (Context, attrs, defstyle);//TODO auto-generated Constructor stub}/** * * Second Implementation way: * * Custom view class: * * Handle touch events, you can use OnT Ouch () * * * * @Overridepublic boolean ontouchevent (Motionevent event) {//TODO auto-generated method Stubfloat rawx = even T.GETRAWX (); Float Rawy = Event.getrawy (); float x = Event.getx (); Float y = event.gety (); LOG.D ("Lvoe", "----on Touch:" + "raw x y = [" + Rawx + "," + Rawy + "],x,y=[" + x+ "," + y + "]"); return super.ontouchevent (event);}}
OnTouch Events in Android events