Sliding switch between left and right (up) based on the launcher's workspace)

Source: Internet
Author: User
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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.