Demo of the custom View series (II) and windmill demo

Source: Internet
Author: User

Demo of the custom View series (II) and windmill demo

The windmills of versions 1.0 and 2.0 have an unsatisfactory effect: When the fingers are lifted, the windmills stop rotating, now Version 3 is to let the windmill continue to rotate for a period of time when the finger is lifted. The idea is as follows:

1) Keep turning the windmill for 5 seconds when your fingers are raised

2) Listen to the MotionEvent. ACTION_UP event and record the upTime of the finger lift.

3) capture the MotionEvent. ACTION_UP event and redraw it for five seconds

According to the preceding instructions, the code of RotationView has been changed as follows (onTouchEvent is modified based on version 2:

/** Time when the finger is lifted **/private long upTime = 0;/** time when the finger is lifted */private final long stopTimeDuration = 5000; @ Overridepublic boolean onTouchEvent (MotionEvent event) {int action = event. getAction (); switch (action) {case MotionEvent. ACTION_MOVE: // re-paint continuously with the move of the finger. // This method uses postInvalidate (); break; case MotionEvent In the UI thread itself. ACTION_UP: // re-paint with the move of the finger. upTime = System. currentTimeMillis (); post (new Runnable (){@ Overridepublic void run () {long duration = System. currentTimeMillis ()-upTime; if (duration = stopTimeDuration) {return;} else if (duration <stopTimeDuration) {post (this) ;}// used in a non-UI thread. Invalidate () ;}}); break;} return true ;}


Of course, there is still a problem with this version of windmill: the speed of the windmill turns is consistent and will not change with the speed of finger movement. This will be solved in the next version, for details, see the custom View series (3)




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.