Android tweened Animations

Source: Internet
Author: User

In the Android development process, in order to better display the application, the application animation, can be very good to achieve this function. If the image changes in the animation have a certain regularity, you can use the automatic generation of images to generate animation, such as the movement, rotation, zooming, and so on. Automatically generate animations of intermediate images, motion tweens, just specify the first and last frames.

The advantage of motion tweens is that you save hard disk space, and the downside is that you can't generate complex animations. This article focuses on the four types of motion tweens that are used frequently: move, zoom, rotate, and transparency.

1. Move motion Tween animations

Moving is a more common animation effect. The motion of a tweened animation can be achieved through an XML file or Java code. In Res/anim, create a new Test_translate.xml file in the file.

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Setxmlns:android= "Http://schemas.android.com/apk/res/android">3     <Translatexmlns:android= "Http://schemas.android.com/apk/res/android"  4 Android:interpolator= "@android: Anim/accelerate_decelerate_interpolator" 5 Android:fromxdelta= "0"Android:toxdelta= " the"Android:fromydelta= "0"Android:toydelta= "0" >6         7     </Translate>8 9 </Set>
Test_translte

Android:interpolator: Represents the animation renderer. You can set up 3 animation renderers: Accelerate_decelerate_interpolator (animation acceleration reducer), first acceleration, then deceleration; Accelerate_interpolator (animation accelerator), animation starts slowly, gradually accelerates ; Decelerate_interpolator (animation reducer): The animation at the beginning of the fastest, gradually slow down.

Android:fromxdelta: The horizontal axis of the starting position of the animation;

Android:fromydelta: The vertical axis of the starting position of the animation;

Android:toxdelta: The horizontal axis of the end position of the animation;

Android:toydelta: The ordinate of the end position of the animation.

Android:duration: The duration of the animation, in milliseconds. The animation moves from the beginning to the end point within the specified time.

tweened Animations load Motion tweens through Animationutils.loadanimation (This,int resid), setanimation bind animations to controls, Animation.start (), Start animations, Animation.setrepeatcount (animation.infinite); cycle display animation.

Three states of a tweened animation: Animation Start, end of animation, animation loop. The interface of listening state is animationlistener,3 by: Onanimationstart, Onanimationend, Onanimationrepeat.

2. Scale motion Tween animations

Scale motion tween animations with the <scale> tag definition.

1     < Scale2         Android:interpolator= "@android: Anim/accelerate_interpolator"3 Android:fromxscale= "1.0"4 Android:fromyscale= "0.0"5 Android:toxscale= "0.0"6 Android:toyscale= "1.0"7 android:duration= "The ">8         9     </ Scale>
Scale

This code enables data to be expanded from top to bottom.

Android:fromxscale: Represents the starting scale scaled along the x-axis.

Android:fromyscale: Represents the starting scale scaled along the y-axis.

Android:toxscale: Represents the end scale scaled along the x-axis

Android:toyscale: Represents the end scale scaled along the y-axis

Android:pivotx: Pivot position scaled along the x-axis

Android:pivoty: Pivot position scaled along the Y axis

3. Rotate the motion tween animation

You can define rotation tween animations through the <roate> tab.

1     <RotateAndroid:interpolator= "@android: Anim/accelerate_interpolator"2 android:fromdegrees= "0"3 android:todegrees= "Max"4 Android:pivotx= "50%"5 Android:pivoty= "50%"6 android:duration= "10000"7 Android:repeatmode= "Restart"8 Android:repeatcount= "Infinite"/>
roate

Android:fromdegrees: The starting angle of the rotation.

Android:todegrees: End angle of rotation

Android:repeatcount: Sets the number of rotations. This property needs to set an integer value and, if 0, does not loop.

Android:repeatmode: Sets the recurrence pattern. Restart, which means that the cycle starts again. Reverse, indicating that an even number of times the animation will be opposite the direction defined by the animation file.

4. Transparency Tween Animations

Sets the transparency tween animation by <alpha the/> tag.

1     <  android:interpolator= "@android: Anim/accelerate_interpolator"2         Android:fromalpha= "1.0"  android:toalpha= "0.2"  android:duration = "$" />
Alpha

Android:fromalpha: Starting transparency for animations

Android:toalpha: transparency of animation end

The attribute value is between 0.0-1.0, 0.0 is fully transparent, and 1.0 is opaque.

Android also has a vibrating animation renderer cycle_interpolator.

Android tweened 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.