Custom view of the Big Windmill series Demo (ii)

Source: Internet
Author: User

The windmill of version 1.0 and version 2.0 has an unsatisfactory effect: when the finger is lifted, the windmill will stop turning, and now version 3 to do is let the finger lift the time to let the windmill continue to rotate for a while, the idea is as follows:

1) Keep the windmill spinning for 5 seconds while your finger is lifted.

2) You need to listen for MOTIONEVENT.ACTION_UP events and record the time the finger is lifted uptime

3) Capture MOTIONEVENT.ACTION_UP events and redraw for five seconds

Based on the above instructions, the following changes are made to the Rotationview code (based on version 2, which mainly modifies the Ontouchevent event:

        /** finger lift Time **/  private long upTime = 0; /** finger lifted when the windmill continued to turn the time **/private final long stoptimeduration =;        @Overridepublic boolean ontouchevent (Motionevent event) {int action = event.getaction (); switch (action) {case MOTIONEVENT.ACTION_MOVE://continues to redraw with the MOVE of the finger//This method uses Postinvalidate () in the UI thread itself; Break;case motionevent.action_up:// Continuously redraw with the move of the finger uptime = System.currenttimemillis ();p Ost (new Runnable () {@Overridepublic void run () {Long Duration = System.currenttimemillis ()-uptime;if (duration ==stoptimeduration) {return;} else if (duration<stoptimeduration) {post (this);} Used in non-UI threads. Invalidate ();}}); break;} return true;}


Of course, this version of the windmill is still problematic: the speed of the windmill rotation is consistent, does not change with the pace of the movement of the finger, this will be resolved in the next version, see the Custom view of the Big Windmill Series (iii)




Custom view of the Big Windmill series Demo (ii)

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.