Android animation principle Summary

Source: Internet
Author: User

Android animation principle Summary
The principle of Computer Animation: 1. Change the image at regular intervals, just like playing a movie. 2. The classification of timer animation is required: attribute animation; view animation; drawable animation-Static Image animation-images of a single frame need to be prepared, and the package size is large. Attribute animation and view animation are considered only when they cannot be completed. Attribute animation and view animation dynamically generate images of each frame without affecting the size of the program. Attribute animation is used to replace view animation. The target object is not limited to view objects, and can be moved even if it is invisible. The essence of property animation is that the timer occurs ----> calculate the new property value ----> set the new value to the property of the target object ----> refresh the target object ----> the UI changes. This process continues to repeat, and an animation will appear. We recommend that you use property animation. Related Classes: 1 Animator base class, which cannot be used directly. 2 ValueAnimator implements most of the functions of the animation framework, but only calculates the attribute value and does not set this value to the object. If it is used, we need to write a listening class to listen to the ValueAnimator event, and then set the attribute value to the object. It can be used, but it is better, consider this when it is not available for better use. 3. A subclass of ObjectAnimator ValueAnimator, which is a better choice. It calculates the property value of the object, and then sets the new value to the property of the object. Use this class most of the time. 4. AnimatorSet indicates an animation Set. It contains multiple animations. These animations can be executed at the same time. They can be executed sequentially or after a while. Use attribute animation class: To make an object move, you must specify this object to ObjectAnimator, specify the attribute to be changed, specify a duration, and specify the animation parameters, such as translation, specify the start and end positions. Constant Speed Translation

ObjectAnimator anim = ObjectAnimator.ofFloat( btnTarget,"translationX",0f,200f);anim.setDuration(2000); anim.start();
Rotate
ObjectAnimator anim = ObjectAnimator .ofFloat( btnTarget, "rotationX", 0f, 180f); anim.setDuration(2000); anim.start(); 
Use an animation collection class:
AnimatorSet set = new AnimatorSet(); ObjectAnimator anim1 = ObjectAnimator.ofFloat(btnTarget,"rotationX",0f,180f); anim1.setDuration(2000); ObjectAnimator anim2 = ObjectAnimator.ofFloat(btnTarget,"rotationX",180f,0f); anim2.setDuration(2000); ObjectAnimator anim3 = ObjectAnimator.ofFloat(btnTarget,"rotationY",0f,180f); anim3.setDuration(2000); ObjectAnimator anim4 = ObjectAnimator.ofFloat(btnTarget,"rotationY",180f,0f); anim4.setDuration(2000);set.play(anim1).before(anim2);set.play(anim3).before(anim4);set.start();
Xml Implementation 1 single Animation
<!--{cke_protected}{C}%3C!%2D%2D%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%2D%2D%3E--> <cke:objectanimator xmlns:android="http://schemas.android.com/apk/res/an droid" android:propertyname="translationX" android:duration="2000" android:valuefrom="0dp" android:valueto="200dp" android:valuetype="floatType"></cke:objectanimator>
Code:
ObjectAnimator anim =(ObjectAnimator)AnimatorInflater.loadAnimator( MainActivity.this,R.animator.rotate_anim); anim.setTarget(btnTarget); anim.start(); 
Multiple animations
<set xmlns:android="http://schemas.android.com/apk/res/android" android:ordering="sequentially"> <cke:objectanimator android:propertyname="rotationX" android:duration="2000" android:valuefrom="0" android:valueto="180" android:valuetype="floatType"> <cke:objectanimator android:propertyname="rotationX" android:duration="2000" android:valuefrom="180" android:valueto="0" android:valuetype="floatType"> </cke:objectanimator></cke:objectanimator></set> 
Code:
AnimatorSet set = (AnimatorSet)AnimatorInflater.loadAnimator( MainActivity.this,R.animator.rotate_anim); set.setTarget(btnTarget); set.start();
 
 
Summary: The animation cannot leave the timer; the android system has three types of animations; the property animation can be used in pure programs or in xml, and the xml must be placed in the res/animator folder; for better reuse, we should try to define an animation in xml. The essence of an attribute animation is to regularly change the attribute value of an object. We can use an animation set class to produce complex animations.

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.