View Basics
View is the base class for all controls in Android, and ViewGroup inherits view.
In Android, the x-axis and y-axis are in the right and bottom squares, respectively.
Position parameters:
(left , top ): View 左上角原始坐标(right, bottom): View 右下角原始坐标(x , y ): View 左上角最终坐标translationX: View 左上角横向偏移量translationY: View 左上角纵向偏移量x = left + translationXy = top + translationY (setX/Y() 时其实就是改变 translationX/Y 的值)width = right - leftheight = bottom - top
Motionevent and Touchslopmotionevent
Typical event: Action_down, Action_move,action_up
The meaning is easy to understand, namely, falling, moving, starting
A single touch triggers a sequence of events:
- Tap the screen and leave the release: down--up
- Click on the screen to swipe and release: down, move->...-> move, up
Get the coordinates of the Click event via motionevent:
- Getx/gety: x and Y coordinates relative to the upper-left corner of the current View
- Getrawx/getrawy: x and Y coordinates relative to the upper-left corner of the phone screen
Touchslop
The minimum distance to slide, if not reached, is not considered sliding, the default 8DP.
Velocitytracker, Gesturedetector and Scrollervelocitytracker
Speed tracking, used to track the speed of your finger during the sliding process.
In the Ontouchevent method of the View:
VelocityTracker velocityTracker = VelocityTracker.obtain();velocityTracker.addMovement(event);velocityTracker.computeCurrentVelocity(1000);// 1000ms内划过的像素数int xVelocity = (int) velocityTracker.getXVelocity();int yVelocity = (int) velocityTracker.getYVelocity();
Recovery:
velocityTracker.clear();velocityTracker.recycle();
Gesturedetector
Gesture detection, which is used to assist in the detection of user clicks, swipes, long presses, double-clicks, and other behaviors.
General listening and sliding correlation, in the ontouchevent self-realization, if the listening double-click, then use Gesturedetector.
Scroller
The elastic sliding object, which is used to realize the elastic slide of the view, which is the sliding of the transition effect, is used in conjunction with the view's Computescroll method.
"Android Development Art Quest" notes-(3) View Event System