Several animation and multiple animations on Android play simultaneously with Scaleanimation application

Source: Internet
Author: User

In the API demo View->animation can find four animation of the demo, the first 3D translate more complex, and finally, the first to talk about the 2nd Interpolator. The activity corresponds to the Animation3.java in the view package, and the layout of the Animation_3.xml.

The layout of the interface is not explained, just a spinner and a textview. is not part of this article.

Mainly explain the next few key statements.

Initialize the animation, from the name of the class can be seen is a transformation view of the location of the animation, the beginning of the parameter, the end of the horizontal axis, the beginning of the ordinate, the end ordinate.

New Translateanimation (0.0f,                  -target.getwidth ()-Targetparent.getpaddingleft ()-                  0.0f, 0.0f );   

Here is the parameter setting for the animation, I added the comment

[Java] View plaincopy a.setduration (1000);//the time it took to set the animationA.setstartoffset (300);//set the animation start delay//Set repeat mode, restart to start again, reverse to return as the original trajectoryA.setrepeatmode (Animation.restart); //set the number of repetitions, infinite for unlimitedA.setrepeatcount (Animation.infinite); //set the access mode of the target based on the user's choice of spinner        Switch(position) { Case0:                  //Accelerated AccessA.setinterpolator (Animationutils.loadinterpolator ( This, Android.                  R.anim.accelerate_interpolator));  Break;  Case1:                  //deceleration intoA.setinterpolator (Animationutils.loadinterpolator ( This, Android.                  R.anim.decelerate_interpolator));  Break;  Case2:                  //accelerated entry. The difference from the first is that when Repeatmode is reverse, the return origin is still acceleratedA.setinterpolator (Animationutils.loadinterpolator ( This, Android.                  R.anim.accelerate_decelerate_interpolator));  Break;  Case3:                  //Go back a little bit and speed it up .A.setinterpolator (Animationutils.loadinterpolator ( This, Android.                  R.anim.anticipate_interpolator));  Break;  Case4:                  //slow down, go back before you finish.A.setinterpolator (Animationutils.loadinterpolator ( This, Android.                  R.anim.overshoot_interpolator));  Break;  Case5:                  //Case 3,4 's binding bodyA.setinterpolator (Animationutils.loadinterpolator ( This, Android.                  R.anim.anticipate_overshoot_interpolator));  Break;  Case6:                  //stop coming back to the vibration a fewA.setinterpolator (Animationutils.loadinterpolator ( This, Android.                  R.anim.bounce_interpolator));  Break; }          //let target start performing this animationTarget.startanimation (a); }  

Here are some of the actions that Android has already preset, and we can customize the XML to achieve better-looking animations, which we'll talk about in the next article.

In addition to Translationanimation, there are alphaanimation, rotateanimation, scaleanimation, using the combination of several matrix actions, can form a series of complex animation effects. Please see the SDK for specific usage.

The whole is relatively simple, just a function call, do not understand the API comments and SDK documentation, nothing difficult to understand.

from:http://blog.csdn.net/lxw1980/article/details/6162985

Animationset can contain multiple animation, but they are executed at the same time , in parallel, not serially.
If there are some settings in the Animationset, such as Duration,fillbefore, it contains the child action is also set,
The settings in the child action will be overwritten.

If Animationset Sets any properties, the its children also set ( forexample, duration or fillbefore), the values of Animationset override the child values. Animationset as=NewAnimationset (true); as.addanimation (TA); translateanimation T1=NewTranslateanimation (2, 200, 8, 300); T1.setduration (2000); as.addanimation (t1); Rotateanimation R1=NewRotateanimation ((float) 1, (float) 0.1); R1.setduration (2000 );//as.addanimation (R1);imgview.setanimation (AS);//as.setduration (6000);//As.setstarttime (+);As.start ();

Scaleanimation Application Explanation

4 animations are available in Android: Alphaanimation transparency animation effect Scaleanimation Zoom animation effect Translateanimation Displacement animation effect rotateanimation rotate animation effect This section explains Scaleanimation animations, scaleanimation (float FromX, float toX, float fromY, float toy,int pivotxtype, float pivotxvalue, in T Pivotytype, float pivotyvalue) parameter description: The copy code code is as follows: float FromX The scaling dimension on x-coordinate at the start of the animation float ToX The scaling dimension on the x-coordinate at the end of the animation float
       
         FromY The scaling dimension of the y-coordinate at the start of the animation float
         ToY The stretch dimension on the y-coordinate at the end of the animation int Pivotxtype animation on the x-axis relative to the object position type float pivotxvalue animation relative to the x-coordinate of the object Start position int pivotytype animation on Y axis relative to object position type float       
         

 Public classMainactivityextendsActivity {ImageView image; Button start; Button Cancel; @Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (r.layout.activity_main); Image=(ImageView) Findviewbyid (r.id.main_img); start=(Button) Findviewbyid (R.id.main_start); Cancel=(Button) Findviewbyid (r.id.main_cancel);/**Set the Zoom animation*/ Finalscaleanimation animation =NewScaleanimation (0.0f, 1.4f, 0.0f, 1.4f, Animation.relative_to_self,0.5f, Animation.relative_to_self, 0.5f); Animation.setduration (2000);//set the duration of an animation/**Common Methods*/ //animation.setrepeatcount (int repeatcount);//set number of repetitions//Animation.setfillafter (Boolean);//whether the animation stays in the finished state after execution//Animation.setstartoffset (long startoffset);//wait time before executionStart.setonclicklistener (NewOnclicklistener () { Public voidOnClick (View arg0) {image.setanimation (animation);/**Start Animation*/Animation.startnow ();} }); Cancel.setonclicklistener (NewOnclicklistener () { Public voidOnClick (View v) {/**End Animation*/animation.cancel ();} }); } } 

Several animation and multiple animations on Android play simultaneously with scaleanimation application details

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.