Animated Animation (Property Animation)

Source: Internet
Author: User

Reprint Please specify http://blog.csdn.net/u014163726/article/details/41210951


The previous article also mentioned that after the introduction of Android 3.0 Property animation, property animation can easily do many of the view animation do not do, today we will learn about property animation.

The previous article mentioned that the view animation just changed the rendering effect of the view, and the property animation is really changing a property, such as the effect.


Compared to the Android animation in detail, we can see the obvious difference, then the property animation is how to use it, MO Panic, the next code to serve.


1,objectanimator

Property animations are not complicated to use and can be said to be much simpler than view animations, with the translation animations above

Mbutton: Object//translationy: Property//300 offset Objectanimator.offloat (Mbutton, "translationy", +). Setduration (2000). Start ();

In a word, the translation animation is realized, but the property animation does not stop there, we modify a property to see.

Mbutton: Object//Translationy: attribute//300 offset objectanimator.offloat (Mbutton, "RotationY", and "Setduration"). Start () ;

May see this many people have doubts, this pass the property name is what, actually use Objectanimator must specify an object and an object property, that is, to have get&set function, if not, it can not be used Objectanimator , but we can use another kind of valueanimator.


2,valueanimator

Let's take a look at an example and use Valueanimator to finish the above effect.

Valueanimator valueanimator = valueanimator.offloat (360); Valueanimator.setduration (2000);
It looks familiar. However, there is no way to use this because you do not specify the object and the property, if you want to complete the animation effectThe Valueanimator.onupdatelistener interface needs to be implemented.

Valueanimator valueanimator = valueanimator.offloat; valueanimator.setduration (2000); Valueanimator.addupdatelistener (New Animatorupdatelistener () {@Overridepublic void Onanimationupdate (valueanimator Animation) {Mbutton.setrotationy (Float) Animation.getanimatedvalue ());});
by Animation.getanimatedvalue () you can get the current value of the property based on the time and the offset, and we'll do whatever we want after we get the current property value. Incidentally, Objectanimator is to inherit Valueanimator.


3,animatorset

Our property animations certainly have set functionality, and the usage is interesting.


Animatorset animatorset = new Animatorset (); Valueanimator valueanimator = valueanimator.offloat; valueanimator.setduration (2000); Valueanimator.addupdatelistener (New Animatorupdatelistener () {@Overridepublic void Onanimationupdate (valueanimator Animation) {Mimageview.setrotationy (Float) Animation.getanimatedvalue ());}); Animatorset.play (Valueanimator). with (Objectanimator.offloat (V, "RotationY"). Setduration (2000)); Animatorset.start ();
Animatorset.play is adding animations. With is simultaneous playback and. Before.after I believe we all know what it is, but this can only be an animation that plays different objects at the same time, if we want the same object to change the properties at the same time.


4,viewpropertyanimator


At the same time call RotationX and rotationy, haha is not very pleasant.

Propertyvaluesholder P1 = propertyvaluesholder.offloat ("RotationX", 360f); Propertyvaluesholder P2 = propertyvaluesholder.offloat ("RotationY", 360f); Objectanimator.ofpropertyvaluesholder (V, P1, p2). Setduration (+). Start ();

About property animations There are interesting things not introduced, we stay in the next issue!



Animated Animation (Property Animation)

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.