Reprinted from: http://www.cnmsdn.com/html/201106/1308775819ID9981.html
You should be familiar with launcher's desktop slide. The best experience should be that you can display the desktop in different locations as your fingers slide,
It is much better than the gesture switching page implemented by viewflinger + animation ~~~~
After analyzing the workspace in the launcher, there is too much code to use (drag, hold ,,,), remove the redundant code in it to achieve the necessary sliding switching screen ....
Create a new scrolllayout class that inherits from viewgroup.
Override onmeasure and onlayout methods:
In the onmeasure method, obtain the layout method of scrolllayout (usually fill_parent), enumerate all the child views, and set their layout (fill_parent ), in this way, each subview in scrolllayout is a page that is full of screens that can be slide.
In the onlayout method, draw each sub-view horizontally. In this way, the height of the view is the same as that of the screen. The width is getchildcount ()-1 View of the screen width.
Add a scroroller to smoothly switch between pages,
Override onintercepttouchevent and ontouchevent to respond to the messages to be captured when the finger is pressed, such as the speed and distance of the stroke. Use the scrollby (int x, int y) method to get the content to be displayed when the slow sliding distance is small. Finally, when the finger is up, the system determines whether to slide one page to the left or one page to the right based on the stroke speed and span, make sure that each user operation ends with a whole sub-view.
Running result: