In XML layout, where is the touch origin of the custom View ?? This is another problem. The learning process is the process of constantly discovering and solving problems. Well, I believe everyone has a deep understanding. This time we will study the touch origin of View.
The following is the core code:
/** * Define Gesture Recognition **/ GestureDetector mGestureDetector; |
/** * Register Gesture Recognition. Of course, this should be initialized in the constructor. **/ PublicVoidMyEvent (){ MGestureDetector =NewGestureDetector ( NewGestureDetector. SimpleOnGestureListener (){ PublicBooleanOnSingleTapUp (MotionEvent e ){ Log.V("OnTouchEvent", "e. getX ():" + e. getX () + "e. getY ():" + e. getY ()); ReturnTrue; } }); } |
/** * Response Touch Screen **/ PublicBooleanOnTouchEvent (MotionEvent event ){ MGestureDetector. onTouchEvent (event ); ReturnTrue; } |
Run:
Click here:
Click to view log
Through observation, we found that this is consistent with the size of the View we defined. The result is self-evident, haha. The following section is a summary.
Download the OK source code