Android Animation analysis

Source: Internet
Author: User

The Android system offers two animations, View Animation and property Animation. View can be subdivided into two animated forms, tweened (tweened animation) and frame (animation). Motion tweens can be used to translate, rotate, zoom, and change the transparency of the view, and frame animation can be similar to the effect of playing a movie. However, the view animation has many restrictions, such as only for the view, only support 4 types of transformations, property animation in the version of Android3.0 (API 11) exit, to compensate for the lack of view animation.

Comparative analysis :
1. View animations can only be used for view objects for objects such as drawable.
2. View only supports translate,rotate, scale Aphla four forms like control width, height, background color is not animated
3. The nature of the view animation is that the control is redrawn in different positions, the control's entity or the original position has not changed. Property animations Change the properties of the view, and the view entity changes.

Example implementations:

Implementing View Animations

The view animation can be done in Android code, or it can be written in an XML file, and Android official documentation is recommended in the XML as much as possible in the completion of the animation. The path to the XML Android project is res/anim/animation. xml

Example: The interface has a button that starts the animation when the button is clicked, the button rotates 360 and the position is shifted 300 pixels

Xml

<?xml version= "1.0" encoding= "Utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"    android: Duration="> "    <rotate android:pivoty="50%"android:pivotx="50%"  Android:fromdegrees="0"android:todegrees="/>                                     "    <Alpha android:fromalpha="1"android:toalpha= "0.3" />           </Set>

Applying in code is

Animation animation = AnimationUtils.loadAnimation(ViewAnimationActivity.this,R.anim.viewanimationactivity_btn_complex1);                btnComplex1.startAnimation(animation);

Property animation

The same property animations are implemented in code and XML implementations, but the documentation suggests that the code is implemented because it is more flexible. Property animation in the Res directory under the Amiator file res/animator/
The system default animation time is 300ms, the refresh frequency is 10ms/f

The base class for Android provides property animations is animator, which has two subclass Valueanimator,animatorset. However, the simplest common class is objectanimator, which inherits from Valueanimator. Use quite simply.

//让按钮的X轴位置横向移动到200px的位置ObjectAnimator animatorX = ObjectAnimator.ofFloat"x",  200f);animatorX.setDuration(2000);animatorX.start();

If you want to implement composite animations, you can combine Animatorset or propertyvaluesholder with Keyframe and Objectanimator. If you want the object to be a property of view view, you can also use the Viewpropertyanimator

btnViewPA.animate().x(50f).y(900f);//可是实现水平方向到50PX  垂直方向到900px

Android Animation analysis

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.