First, the view's positional parameters (are relative to the parent container's location)
The position of 1.View is determined by the upper-left corner, the lower-right corner point. The corresponding (upper left X-getleft, upper left y-gettop, lower right x-getright, lower right y-getbottom).
2.View offset (translation): Indicates the offset of the upper-left corner relative to the parent container (the difference between the current position and the moved position is called an offset), which defaults to 0. (The test can only be changed by settranslation translation, the motion tween animation.xml invalid) through gettransaltion get x, y
3.View getx (), GetY (all the points in the upper-left corner): x = left + Translationx, the x-coordinate of the upper-right corner plus the x offset, y = top + translationy, (the coordinate of the upper-left corner, plus y offset)
4.View Getscalex (), Getscaley (): The coordinates of the upper-left corner of the view's contents.
Explain:
Ii. introduction of Velocitytracker, Gesturedetector, Scroller
1.VelocityTrancker
Action: Speed tracking, used to track the speed of the finger during sliding (both horizontal and vertical speed)
Use: ①, adding event events to the Velocity object ②, setting time: Refers to the number of pixels that have crossed over a period of time ③, gets the x, y direction (positive from left to right, positive from top to bottom)
Instance:
Public classMainactivityextendsappcompatactivity {Private Static FinalString TAG = "Mainactivity"; PrivateVelocitytracker Mvelocitytracker =NULL; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); //Get VelocityMvelocitytracker =Velocitytracker.obtain (); } @Override Public Booleanontouchevent (Motionevent event) {//the event object is in the charge of the objectmvelocitytracker.addmovement (event); Switch(Event.getaction ()) { CaseMotionevent.action_move://set the time interval: speed refers to the number of pixels that a finger has crossed over a period of timeMvelocitytracker.computecurrentvelocity (1000); //Print SpeedLOG.D (TAG, "slide x pixels in 1 Seconds" +mvelocitytracker.getxvelocity () + "y pixels" +mvelocitytracker.getyvelocity ()); Break; default: Break; } return Super. Ontouchevent (event); }}
mainactivity
Note: When the Getxvelocity () method is called, the average speed is returned. (Suppose I set 1 meow, which means not to wait a second before returning to Getxvelocioty (), but when you call Getxvelocity () to use math to calculate the speed per second).
Slide of view