Custom view, use the paint canvas some of the temperature, propertyanimation in the Objectanimator (animation three, "big sister" rotation jump)

Source: Internet
Author: User

Reprint please indicate the source: Wang 亟亟 's way of Daniel

On a comparison of some of the basic view Animation this will be selected propertyanimation part of the function to say, because its sub-class is still quite a lot of, want to divide the space more points, and then can be said fine point

First on the effect of running (GIF eat animation, forgive me, everyone can run under their own)

This article will mainly talk about the following parts
- Objectanimator
- Animatorset
- Propertyvaluesholder
And some of the knowledge points associated with it

What is the difference between property animation and our view animation yesterday?

It can change the effect of animation.

What do you mean, show effect?
Example: I translate an animation from (0,0) to (200,200) in the case of using view animation, I can only use one animation effect at the same time, the implementation is relatively single, difficult to meet our real scene, but the property animation can be used to " Combo Fist "

List Property Animation Some common subclasses and methods

Objectanimator Animation's execution class (the protagonist of this article)

Objectanimator object Animation, when a view has a getter, setter method for a property, you can use that animation to manipulate this property.

Valueanimator Animation's execution Class (Objectanimator's parent Class)

The scope of operation is relatively wide, through interpolator and typeevaluator to get the value of a certain time, then use the listener, listen to the change of value, do the corresponding operation.

It's important to be able to listen to animations

Animatorset Animation Collection

Used to control the execution of the animation/at the same time, each animation is executed successively.

Animatorinflater

Loading XML animations, this article is an example of Java code implementation

Objectanimator

Compared to the Valueanimator class, Objectanimator is more practical because it can actually work on an object. However, Objectanimator is inherited from the valueanimator, so the main method or valueanimator in the realization. So let's take a look at the use of objectanimator. Common methods include these: Offloat (), Ofint (), Ofobject (), Ofargb (), Ofpropertyvaluesholder ().

Rotate around the x/Y axis

Logutils. D("--->makeanim 4 objectanimator rotate along the x axis");Objectanimator. Offloat(ImageView,"RotationX",0.0F360.0F. Setduration( -). Start();Logutils. D("--->makeanim 5 objectanimator rotate along the y axis");Objectanimator. Offloat(ImageView,"RotationY",0.0F150.0F0.0F. Setduration( -). Start();

Zoom in and out along the X/Y axis

Logutils. D("--->makeanim 6 objectanimator zoom in on the x-axis.");Objectanimator. Offloat(ImageView,"ScaleX",1.0F1.5F1.0F. Setduration( -). Start();Logutils. D("--->makeanim 7 objectanimator zoom in the y-axis.");Objectanimator. Offloat(ImageView,"ScaleY",1.0F1.5F1.0F. Setduration( -). Start();

Move along the X/y Zhou Ping, and repeat the implementation

Logutils. D("--->makeanim 8 objectanimator Shift along the x-axis");Objectanimator. Offloat(ImageView,"Translationx",0.0F200.0F0.0F. Setduration( -). Start();Logutils. D("--->makeanim 9 objectanimator 2 times along the y-axis");Objectanimator Objectanimator = Objectanimator. Offloat(ImageView,"Translationy",0.0F200.0F0.0F;Objectanimator. Setduration( -);Objectanimator. Setrepeatcount(2);//number of repetitionsObjectanimator. Setrepeatmode(Valueanimator. RESTART);//Repeat ModeObjectanimator. Start();

Achieving complex results requires the assistance of the following methods

setsetsetsetsetsetsetEvaluator():设置动画过度的评估者。

So how do those combination animations work?

Animatorset

Animationset provides a mechanism for combining multiple animations into one, and sets the timing relationships of the animations in the group, such as simultaneous playback, sequential playback, and so on.

This class provides a play () method, if we pass a animator object (Valueanimator or Objectanimator) to this method An instance of Animatorset.builder will be returned, and the following four methods are included in the Animatorset.builder:

After (Animator anim) inserts an existing animation into the incoming animation after it executes
After (long delay) The existing animation is delayed by a specified millisecond after execution
Before (Animator Anim) executes an existing animation before inserting it into an incoming animation
With (Animator Anim) performs both existing and incoming animations

Well, let's experiment.

Rotate and drift to an x, Y coordinate

Logutils. D("--->makeanim objectanimator rotates along the x-axis of the y -axis");Objectanimator ObjectAnimator1 = Objectanimator. Offloat(ImageView,"Translationy",0.0F250.0F0.0F;Objectanimator ObjectAnimator2 = Objectanimator. Offloat(ImageView,"Translationx",0.0F250.0F0.0F;Objectanimator ObjectAnimator3 = Objectanimator. Offloat(ImageView,"RotationY",0.0F360.0F;Animatorset animationset = new Animatorset ();//Combo AnimationAnimationset. Play(ObjectAnimator1). with(OBJECTANIMATOR2). with(ObjectAnimator3);Animationset. Setduration(4000);Animationset. Setstartdelay( the);Animationset. Start();

Because 3 animations are simultaneous, use the with connection

Well, let's try another order.

LOGUTILS.D ("--->makeanim objectanimator first, zoom in, rotate in the process, and fade away."); Objectanimator ObjectAnimator4 = Objectanimator.offloat (ImageView,"ScaleX",1.0f,2.0f,1.0f); Objectanimator ObjectAnimator5 = Objectanimator.offloat (ImageView,"ScaleY",1.0f,2.0f,1.0f); Objectanimator ObjectAnimator6 = Objectanimator.offloat (ImageView,"Alpha",1.0f,0.2f,1.0f); Objectanimator objectAnimator7 = Objectanimator.offloat (ImageView,"RotationX",0.0f,360.0f); Animatorset AnimationSet1 =NewAnimatorset ();//Combo animationAnimationset1.setduration (4000); Animationset1.play (ObjectAnimator4). with (ObjectAnimator5). with (OBJECTANIMATOR7). before (OBJECTANIMATOR6); Animationset1.start ();

First, x, y to zoom in, rotate, and then disappear.

Propertyvaluesholder

In addition to Animatorset can also use Propertyvaluesholder to show "combo Boxing" is only propertyvaluesholder effect is simultaneous, that is, similar to a number with the effect

LOGUTILS.D ("--->makeanim objectanimator zoom in, rotate, fade Away"); Propertyvaluesholder Valuesholder = Propertyvaluesholder.offloat ("ScaleX",1.0f,2.0f,1.0f); Propertyvaluesholder ValuesHolder1 = Propertyvaluesholder.offloat ("ScaleY",1.0f,2.0f,1.0f); Propertyvaluesholder ValuesHolder2 = Propertyvaluesholder.offloat ("Alpha",1.0f,0.2f,1.0f); Propertyvaluesholder ValuesHolder3 = Propertyvaluesholder.offloat ("RotationY",0.0f,360.0f); Objectanimator Objectanimator8=objectanimator.ofpropertyvaluesholder (Imageview,valuesholder,valuesholder1, VALUESHOLDER2,VALUESHOLDER3); Objectanimator8.setduration (4000); Objectanimator8.start ();

The animation effect is the last animation.

not to be continued

Source Address: Https://github.com/ddwhan0123/BlogSample/blob/master/ViewAnimDemo.zip

Related references can be seen http://www.wfuyu.com/technology/20853.html

Custom view, use the paint canvas some of the temperature, propertyanimation in the Objectanimator (animation three, "big sister" rotation jump)

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.