Animation (Animation) It (flashing, left and right sway, seesaw and other effects)

Source: Internet
Author: User

One side to the other side of the effect: (shown here is not so smooth)



I. Continuation of the broadcast (Do not know what name is good, is to play animation A, and then play animation B)

There are two ways of doing this.

The first kind . Animate two animations, A and B, then play animation A and set the Animationlistener of a. When the Onanimationend trigger (that is, a play is complete), start playing B.

        Animation1.setanimationlistener (New Animation.animationlistener () {@Overridepublic void Onanimationstart (Animation Animation) {} @Overridepublic void Onanimationrepeat (animation animation) {} @Overridepublic void Onanimationend ( Animation Animation) {Animation2.start ();}});

another , write an animation set Animationset, in which animation A and B are defined, set Startoffset for animation B, whose value is the time required for the previous animation to play.


Here for example, animation A is transparent from 0.1 to 1.0, animation B is transparent from 1.0 to 0.1, using the following animation set you can see the whole process of change.

<?

XML version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" >< Alpha android:fromalpha= "0.2" android:toalpha= "1.0" android:duration= "Up" /> < Alpha android:startoffset= "android:fromalpha=" 1.0 " android:toalpha=" 0.2 " android: duration= "/></set>"


The android:startoffset= "3000" indicates a delay of 3 seconds before running.

If you remove the android:startoffset= "3000", you will not see any effect. Since two animations will play at the same time.


Second, the circulation

Sometimes, we may need to achieve a picture flicker function (for example, the emergency alarm function in the weather forecast), or sometimes we need to achieve the picture left and right shaking, we need to loop animation to achieve.

Same. There are also two ways.

First, set two animations A and B, and animation A is transparency 0-1. Animation B is 1-0, then listen to all two animations, and A ends with B. b End run A. Infinite loop ...

Another, using animation's setrepeatcount, Setrepeatmode to achieve animation cycle.


For example, flashing (transparent light, dark, dark, light, so loop)

        Flashing        alphaanimation alphaAnimation1 = new Alphaanimation (0.1f, 1.0f);        Alphaanimation1.setduration (+);        Alphaanimation1.setrepeatcount (animation.infinite);        Alphaanimation1.setrepeatmode (animation.reverse);        Iv.setanimation (alphaAnimation1);        Alphaanimation1.start ();

Alphaanimation1.setrepeatcount (Animation.infinite); Indicates repeated times.

can also set the number of detailed repetition, for example alphaanimation1.setrepeatcount (5);

Alphaanimation1.setrepeatmode (animation.reverse); indicates that the animation ends and runs again.

There are two kinds of values for this method, RESTART and REVERSE.

Restart means starting from the beginning, reverse means to rewind from the end.


Too lazy to screen video, similar to the following effect:



For example, sway around

        Swing        translateanimation alphaAnimation2 = new Translateanimation (150f, 350f,.);        Alphaanimation2.setduration (+);        Alphaanimation2.setrepeatcount (animation.infinite);        Alphaanimation2.setrepeatmode (animation.reverse);        Iv.setanimation (alphaAnimation2);        Alphaanimation2.start ();

where IV is ImageView.


All right. Wrote it so.



Animation (Animation) It (flashing, left and right sway, seesaw and other effects)

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.