Android animation (1)

Source: Internet
Author: User

Android Tweened Animation has four types

Alpha: fade in and fade out

Scale: Scaling Effect

Rotate: rotation effect

Translate: Moving Effect

Procedure for using Tweened Animations

1. Create an AnimationSet object

2. Create the expected Animation object as needed

3. Set the corresponding data for the Animation object based on the needs of the software Animation.

4. Add the Animation object to the AnimationSet object.

5. Make the control object start executing the AnimationSet

Alpha Animation

[Java]
AnimationSet as = new AnimationSet (true );
AlphaAnimation al = new AlphaAnimation (1, 0 );
// 1 indicates completely opaque, and 0 indicates completely transparent
Al. setDuration (3000 );
As. addAnimation (al );
Iv. startAnimation ();

AnimationSet as = new AnimationSet (true );
AlphaAnimation al = new AlphaAnimation (1, 0 );
// 1 indicates completely opaque, and 0 indicates completely transparent
Al. setDuration (3000 );
As. addAnimation (al );
Iv. startAnimation (as); Rotate Animation

[Java]
AnimationSet as = new AnimationSet (true );
RotateAnimation al = new RotateAnimation (0,720, Animation. RELATIVE_TO_PARENT, 0.5f, Animation. RELATIVE_TO_PARENT, 0.5f );
// The Rotation Angle of the first two parameters. The following parameters determine the rotation center.
// Animation. ABSOLUTE: ABSOLUTE Coordinate
// Animation. RELATIVE_TO_PARENT: relative to the parent Control
// Animation. RELATIVE_TO_SELF: relative to yourself
Al. setDuration (3000 );
As. addAnimation (al );
Iv. startAnimation ();

AnimationSet as = new AnimationSet (true );
RotateAnimation al = new RotateAnimation (0,720, Animation. RELATIVE_TO_PARENT, 0.5f, Animation. RELATIVE_TO_PARENT, 0.5f );
// The Rotation Angle of the first two parameters. The following parameters determine the rotation center.
// Animation. ABSOLUTE: ABSOLUTE Coordinate
// Animation. RELATIVE_TO_PARENT: relative to the parent Control
// Animation. RELATIVE_TO_SELF: relative to yourself
Al. setDuration (3000 );
As. addAnimation (al );
Iv. startAnimation (as); Scale Animation


[Java]
AnimationSet as = new AnimationSet (true );
ScaleAnimation al = new ScaleAnimation (, Animation. RELATIVE_TO_SELF, 0.5f, Animation. RELATIVE_TO_SELF, 0.5f );
// The first four parameters are the size from X to Y, and the size from Y. The following parameters are the center point of scaling.
Al. setDuration (3000 );
As. addAnimation (al );
Iv. startAnimation ();

AnimationSet as = new AnimationSet (true );
ScaleAnimation al = new ScaleAnimation (, Animation. RELATIVE_TO_SELF, 0.5f, Animation. RELATIVE_TO_SELF, 0.5f );
// The first four parameters are the size from X to Y, and the size from Y. The following parameters are the center point of scaling.
Al. setDuration (3000 );
As. addAnimation (al );
Iv. startAnimation ();
Translate Animation

[Java]
AnimationSet as = new AnimationSet (true );
TranslateAnimation al = new TranslateAnimation (Animation. RELATIVE_TO_SELF, 0, Animation. RELATIVE_TO_SELF, 2, Animation. Parent, 0, Animation. RELATIVE_TO_SELF, 2 );
Al. setDuration (3000 );
As. addAnimation (al );
Iv. startAnimation ();

AnimationSet as = new AnimationSet (true );
TranslateAnimation al = new TranslateAnimation (Animation. RELATIVE_TO_SELF, 0, Animation. RELATIVE_TO_SELF, 2, Animation. Parent, 0, Animation. RELATIVE_TO_SELF, 2 );
Al. setDuration (3000 );
As. addAnimation (al );
Iv. startAnimation ();
There are several ways to use Animation

SetFillAfter (boolean fillAfter)

If the fillAfter value is true, after the animation ends, the control stays in the status after execution.

SetFillBefore (boolean fillBefore)

If the fillBefore value is true, after the animation ends, the control stays in the starting state of the animation.

SetStartOffset (long startOffset)

Set the waiting time before the animation is executed by the animation control.

SetRepeatCount (int repeatCount)

Set the number of repeated animation executions


 

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.