Android alphaanimation \ translateanimation multiple sets of animation loops + flashing after a single animation ends

Source: Internet
Author: User

Animation cycle: the imageview fades in first, waits for the random time, and then fades out. After waiting for the random time, repeat the previous operation.

Imageview IMG = new imageview (this); // create imageviewimg. setimageresource (R. drawable. IMG); // specify the image alphaanimation alphainanim = new alphaanimation (0.0f, 1.0f); // create an animation alphainanim. setduration (1000); // specifies the animation duration alphainanim. getfillafter (true); // specifies whether to fill in the Ending position of the source image after the animation ends to prevent flickering trapalphainanim. setanimationlistener (New animationlistener () // sets the animation listener {@ overridepublic void onanimationstart (animation) {// todo Au To-generated method stub} @ overridepublic void onanimationend (animation) {// todo auto-generated method stublong delay = m_rand.nextlong () % 2000; // random wait time message = new message (); // create a message object message. what = msg_trap_in_anim_end; // sets the message content mhandler. sendmessagedelayed (message, delay); // sends a message and starts the fade-out animation} @ overridepublic void onanimationrepeat (animation) {// todo auto-generated method stub }); Alphaanimation alphaoutanim = new alphaanimation (1.0f, 0.0f); // create a fade-out animation alphaoutanim. setduration (2000); // specifies the animation duration alphaoutanim. getfillafter (true); // specifies whether to fill in the Ending position of the source image after the animation ends to prevent flashing alphaoutanim. listener (New animationlistener () // sets the animation listener {@ overridepublic void onanimationstart (animation) {// todo auto-generated method stub} @ overridepublic void onanimationend (animation) {// todo Auto-generated method stublong delay = m_rand.nextlong () % 2000; // random wait time message = new message (); // create a message object message. what = msg_trap_out_anim_end; // sets the message content mhandler. sendmessagedelayed (message, delay); // sends a message and starts the fade-in animation} @ overridepublic void onanimationrepeat (animation) {// todo auto-generated method stub}); IMG. startanimation (alphainanim); // start the fade-in animation public final static int msg_trap_in_anim_en D = 9; // message: Public final static int msg_trap_out_anim_end = msg_trap_in_anim_end + 1 after the animation fades out; // message: Private handler mhandler = new handler () after the animation ends () {public void handlemessage (Message MSG) {Switch (MSG. what) {Case msg_trap_in_anim_end: {If (alphaoutanim! = NULL & m_trapimg! = NULL) {alphaoutanim. Reset (); IMG. startanimation (alphaoutanim);} break;} case msg_trap_out_anim_end: {If (alphainanim! = NULL & m_trapimg! = NULL) {alphainanim. Reset (); IMG. startanimation (alphainanim) ;}break ;}super. handlemessage (MSG );}};

The above is an infinite loop combination animation.

Flash protection:

Alphainanim. getfillafter (true); // specifies whether to use the source image to fill in the Ending position after the animation ends to prevent flashing.

For more information, see the getfillafter function.

Reference: (the first three items)

Http://fujian0910.blog.51cto.com/1706151/751552

Http://hi.baidu.com/j_fo/blog/item/66b2700e1cfcedea7bcbe1a4.html

Http://jakend.iteye.com/blog/1150065

Http://www.cnblogs.com/feisky/archive/2010/01/11/1644482.html

Http://topic.csdn.net/u/20110210/10/b6850b89-65eb-4669-bd3e-95b10fc184cc.html

Http://topic.csdn.net/u/20120305/14/badd9a4c-fe23-486b-9582-362e2f180db9.html

Http://lovehong0306.iteye.com/blog/1511089

Http://blog.csdn.net/hellogv/article/details/6264706

Related Article

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.