Android animation effect

Source: Internet
Author: User

The Android SDK provides three types of animations: Compensation animation, frame-by-frame animation, and interpolation attribute animation. Next we will first introduce the first animation effect-the animation of the population.

The compensation animation can be applied to the View, so that developers can define changes to the size, position, rotation, and transparency to make the View content work.

The Animation is created using the Animation class. It has four direct sub-classes for different Animation effects:

AlphaAnimation gradient transparency animation effect, that is, fade-in and fade-out effect

ScaleAnimation: Scaling animation effect with gradient size, that is, Scaling Effect

TranslateAnimation

RotateAnimation: transfer the animation effect, that is, the animation effect.

There are two ways to use the effect of the animation to fill the room. The first is to set the animation effect in the XML file, and the second is to set it in the Java code. The following two methods are described respectively:

1. Set the method in the XML file:

Create an anim folder in the res directory of the Android project, and then create firstanim. xml in the anim folder to add the animation effect configuration code. The sample code is as follows:

[Html]

Android: fromalphi = "0.1"

Android: toAlpha = "1.0"

Android: duration= "3000"

/>

Android: interpolator =

"@ Android: anim/accelerate_decelerate_interpolator"

Android: fromXScale = "0.0"

Android: toXScale = "1.4"

Android: fromYScale = "0.0"

Android: toYScale = "1.4"

Android: Required Tx = "50%"

Android: Ty = "50%"

Android: fillAfter = "false"

Android: duration = "700"/>

Android: fromXDelta = "30"

Android: toXDelta = "-80"

Android: fromYDelta = "30"

Android: toYDelta = "300"

Android: duration= "2000"

/>

Android: interpolator = "@ android: anim/accelerate_decelerate_interpolator"

Android: fromDegrees = "0"

Android: toDegrees = "+ 350"

Android: Required Tx = "50%"

Android: Ty = "50%"

Android: duration = "3000"/>

Android: fromalphi = "0.1"

Android: toAlpha = "1.0"

Android: duration= "3000"

/>

Android: interpolator =

"@ Android: anim/accelerate_decelerate_interpolator"

Android: fromXScale = "0.0"

Android: toXScale = "1.4"

Android: fromYScale = "0.0"

Android: toYScale = "1.4"

Android: Required Tx = "50%"

Android: Ty = "50%"

Android: fillAfter = "false"

Android: duration = "700"/>

Android: fromXDelta = "30"

Android: toXDelta = "-80"

Android: fromYDelta = "30"

Android: toYDelta = "300"

Android: duration= "2000"

/>

Android: interpolator = "@ android: anim/accelerate_decelerate_interpolator"

Android: fromDegrees = "0"

Android: toDegrees = "+ 350"

Android: Required Tx = "50%"

Android: Ty = "50%"

Android: duration = "3000"/>

In the onCreate () method of the Activity, obtain the animation effect configured in XML. The Code is as follows:

[Java]

Animation animation = AnimationUtils. loadAnimation (this, R. anim. firstanim );

Animation animation = AnimationUtils. loadAnimation (this, R. anim. firstanim );

If the animation effect is used on an ImageView, you can refer to the following code:

[Java]

ImageView. startAnimation (animation );

ImageView. startAnimation (animation); 2. Set the method in Java code:

Take AlphaAnimation as an example,

[Java]

// First declare an object of Animation

Private Animation alpha;

// Instantiate this object in the onCreate () method of Activity

Alpha = new AlphaAnimation (0.1f, 1.0f );

// Set the animation duration to 3 seconds.

Alpha. setDuration (3000 );

// First declare an object of Animation

Private Animation alpha;

// Instantiate this object in the onCreate () method of Activity

Alpha = new AlphaAnimation (0.1f, 1.0f );

// Set the animation duration to 3 seconds.

Alpha. setDuration (3000 );

If the animation effect is used on an ImageView, you can refer to the following code:

[Java]

ImageView. startAnimation (alpha );

ImageView. startAnimation (alpha );

Related Article

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.