Android Open Source-nineoldandroids

Source: Internet
Author: User

Open Source Address: https://github.com/JakeWharton/NineOldAndroids

Introduction: Nineoldandroids is a framework that supports Android animations developed in the low version, including a series of Viewanimator,objectanimator,

Viewpropertyanimator and other APIs, resolves an issue in which the tween animation move only shows the move effect, not the real component.


1) Create Objectanimator
Objectanimator anim1=objectanimator.offloat (balls.get (0), "Y", 0f,getheight ()-balls.get (0). GetHeight ()). Setduration (500);
Call Start Animation.start ();
Cloning Objectanimator Anim2=anim1.clone ();


2) Defining animation groups

Objectanimator Animdown=objectanimator.offloat (Balls.get (2), "Y", 0f,getheight ()-balls.get (2). GetHeight ()). Setduration, Objectanimator animup=objectanimator.offloat (Balls.get (2), "Y", GetHeight ()-balls.get (2). GetHeight (), 0f). Setduration (500); Animatorset s1=new Animatorset ();
Make the animation coherent s1.playsequentially (ANIMDOWN,ANIMUP);
Start the animation time consistent animation.playtogether (ANIM1,ANIM2,S1);

3) value animation (Animatorinflater layout loader)

Valueanimator alphaanimator= (valueanimator) animatorinflater.loadanimator (animationloading.this,r.anim.animator) ; Alphaanimator.settarget (Balls.get (1)); Alphaanimator.addupdatelistener (new Animatorupdatelistener () {@ overridepublic void Onanimationupdate (Valueanimator animation) {Balls.get (1). Setalpha ((Float) Animation.getanimatedvalue ());});


4) Animation set
animatorset s1= (animatorset) animatorinflater.loadanimator (animationloading.this,r.anim.animator_set);
S1.settarget (Balls.get (2));
Object Animation (move/color change)
objectanimator s2= (objectanimator) animatorinflater.loadanimator (Animationloading.this, R.anim.color_animator );
S2.settarget (Balls.get (3));
Define Animation order
((animatorset) animation). Play (ANIMX). before (Animy);//animx in front of Animy
((animatorset) animation). Play (ANIMX). with (Animy);//animx and Animy perform synchronously
//ARC accelerator
new Cycleinterpolator (2.0f)


//define various properties > summaries
Propertyvaluesholder animy=propertyvaluesholder.offloat ("Y", Balls.get (1). GetY (), getheight ()-100); Propertyvaluesholder alpha=propertyvaluesholder.offloat ("Alpha", 1.0f,.5f); Objectanimator pvhAlpha= Objectanimator.ofpropertyvaluesholder (Balls.get (1), Animy,alpha). setduration (1000);
//Set zoom animation
Propertyvaluesholder widthholder=propertyvaluesholder.offloat ("width", ball.getwidth (), Ball.getwidth () * *); Propertyvaluesholder heightholder=propertyvaluesholder.offloat ("Height", ball.getheight (), Ball.getHeight () * *); Propertyvaluesholder xpt=propertyvaluesholder.offloat ("x", Ball.getx (), Ball.getx ()-ball_size/2f); Propertyvaluesholder ypt=propertyvaluesholder.offloat ("Y", ball.gety (), ball.gety ()-ball_size/2f); ObjectAnimator Sumanimator=objectanimator.ofpropertyvaluesholder (Ball,widthholder,heightholder,xpt,ypt). SetDuration (750); Sumanimator.setrepeatmode (Valueanimator.reverse); Sumanimator.setrepeatcount (1);//set Repeatcount=1 to revert to the original
//Transform the trajectory of the animation
bounceanim.reverse ();

***************************************objectanimator component Application *************************************

Displacement: The units of motion are pixels, and you can specify a range of positions
Objectanimator.offloat (Target, "Translationx", 0,50). Setduration (Duration). Start (); Objectanimator.offloat (target , "Translationy", 0,50,-50,0). Setduration (Duration). Start ();
Scaling: 1.0f represents 1 time times the original length/width, the same as the other. All multiples are multiplied by the earliest set width
Objectanimator.offloat (Target, "ScaleX", 1,2,1). Setduration (Duration). Start (); Objectanimator.offloat (Target, " ScaleY. Setduration (Duration). Start ();
transparency: 1.0f means opaque 0 means full transparency
Objectanimator.offloat (target, "alpha", 1,0,1). Setduration (Duration). Start ();
Rotation:
Objectanimator.offloat (Target, "RotationX", 0,180,0). Setduration (Duration). Start (); Objectanimator.offloat (target , "RotationY", 0,360). Setduration (Duration). Start (); Objectanimator.offloat (target, "rotation", 0,180,0). Setduration (Duration). Start ();
set the transform center; Of course, multiple animations can combine transformations
Viewhelper.setpivotx (Target,target.getwidth ()/2); Viewhelper.setpivoty (Target,target.getheight ()/2);

***************************************viewpropertyanimator component Application ********************************** ***
Animate (target) setduration, animate (Animatingbutton). Alpha (0), animate (Animatingbutton). x (XValue). Y ( Yvalue); animate (Animatingbutton). Rotationyby (720);


Android Open Source-nineoldandroids

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.