I. How the sliding effect is produced
The essence of sliding a view is actually moving a view, changing its position when the money is, his principle and animation effect is very similar, is through constantly changing the view coordinates to achieve this effect, dynamic and constantly change the view coordinates, so that the view following the user touch sliding and sliding
But before you explain the slide effect, you need to know about the Windows coordinate system in Android and the touch events of the screen--motionevent
1.Android coordinate system
In physics, to describe the movement of an object, it is necessary to select a reference system, the so-called sliding, is the movement relative to the reference system, in Android, the system will be the top left corner of the screen as the origin of the android coordinates, from this point to the right is the x-axis positive direction, from this point down is the y-axis
The system provides Getlocationonscreen (intlocation[]) to get the location in android coordinates, that is, the android coordinates in the upper-left corner of the view, in addition, using GETRAWX () in touch events, Getrawy () method to get coordinates is also the coordinates in the Android coordinate system.
2. View coordinate system
In addition to the above-mentioned coordinate system in Android, there is also a view coordinate system, he describes the child view in the parent view of the location relationship, the two coordinate systems are not complex or contradictory, their role is mutually reinforcing, similar to the Android coordinate system, the view coordinate system is the same as the origin point to the right x positive direction, The Y method is down to the origin, except in the view coordinate system, where the origin is no longer the upper-left corner of the screen in the Android coordinate system, but the upper-left corner of the parent view is the origin of the coordinates.
Coordinates obtained through getx,gety in touch events are coordinates in view coordinates
3. Touch Event--motionevent
Touch event Motionevent in the user's interaction, occupy a pivotal position, learn the touch event is the basis of the following content, first of all, we look at some of the motionevent encapsulated constants, he defined the different types of touch events.
Typically, we get the type of the touch event in the Ontouchevent (Motionevent event) method through Event.getaction (), and use switch to determine that the code module is fixed
Without multi-touch, you can usually use the following code to complete the listening of touch events, but this is just a code module, and we'll talk about specific logic later.
In Android, the system provides a lot of methods to get coordinate values, relative distance, etc., the method is rich is good, but also to the beginner has brought many problems, do not know under what circumstances use summed up people some common API
Android Elite Biography-fifth chapter: Android Scroll analysis