Android simple animation effect and android Animation

Source: Internet
Author: User

Android simple animation effect and android Animation

A1.xml fade-out effect


<? Xml version = "1.0" encoding = "UTF-8"?>


<Set xmlns: android = "http://schemas.android.com/apk/res/android">


<Alpha
Android: duration= "500"
Android: fromalphi = "1.0"
Android: toAlpha = "0.0"/>
</Set>
<! -- FromAlpha: transparency at start toAlpha: transparency at end duration: animation duration -->


A2.xml fade-in effect:


<? Xml version = "1.0" encoding = "UTF-8"?>


<Set xmlns: android = "http://schemas.android.com/apk/res/android">


<Alpha
Android: duration= "500"
Android: fromalphi = "0.0"
Android: toAlpha = "1.0"/>
</Set>
Rotate. xml rotation effect:


<? Xml version = "1.0" encoding = "UTF-8"?>


<Set xmlns: android = "http://schemas.android.com/apk/res/android">


<Rotate
Android: duration= "10000"
Android: fromDegrees = "300"
Android: interpolator = "@ android: anim/accelerate_decelerate_interpolator"
Android: Required Tx = "10%"
Android: Ty = "100%"
Android: toDegrees = "-360"/>
</Set>
<! --
When fromDegrees starts, the angle toDegrees is the starting position of the X and Y coordinates of the animation relative to the object,
50% indicates the online point position on the X or Y of the object.
-->


Scale. xml Scaling:


<? Xml version = "1.0" encoding = "UTF-8"?>


<Set xmlns: android = "http://schemas.android.com/apk/res/android">


<Scale
Android: duration= "10000"
Android: fromXScale = "0.0"
Android: fromYScale = "0.0"
Android: interpolator = "@ android: anim/decelerate_interpolator"
Android: Required Tx = "50%"
Android: Ty = "50%"
Android: repeatCount = "1"
Android: repeatMode = "reverse"
Android: startOffset = "0"
Android: toXScale = "1.5"
Android: toYScale = "1.5"/>
</Set>
<! --
Interpolator specifies the animation insertor. Common acceleration and deceleration insertor accelerate_decelerate_interpolator,
The accelerator plug-in accelerate_interpolator and the decelerate_interpolator.
FromXScale, fromYScale, scale X and Y before the animation starts, 0.0 is not displayed, 1.0 is normal size toXScale, toYScale,
The final scaling factor of the animation. The value 1.0 is the normal size. If the animation size is greater than 1.0, the starting position of the animated Tx is enlarged. The percentage relative to the screen,
Both of them are 50%, indicating that the animation starts startOffset from the middle of the screen. The interval between multiple executions of the animation. If the animation is executed only once, it will be paused before execution,
In the unit of millisecond duration, the time consumed by an animation effect, in the unit of milliseconds. The smaller the value, the faster the animation speed, the repeatCount, and the repeated animation count,
The animation will execute this value + 1 repeatMode, the animation repetition mode, and the reverse is reverse. When the occasional execution is performed, the animation will be in the opposite direction.
Restart indicates re-execution, and the direction remains unchanged.
-->


Translate. xml:


<? Xml version = "1.0" encoding = "UTF-8"?>


<Set xmlns: android = "http://schemas.android.com/apk/res/android">


<Translate
Android: duration= "10000"
Android: fromxdel= "320"
Android: fromYDelta = "480"
Android: toXDelta = "0"
Android: toYDelta = "0"/>
</Set>
<! --
FromXDelta and fromYDelta are coordinates X and Y at the start of the animation. The coordinates in the lower right corner of the screen are X: 320, Y: 480 toXDelta and toYDelta.
Coordinates of X and Y at the animation end
-->


The animation effect is defined in the xml file under the anim directory. in the program, use AnimationUtils. loadAnimation (Context context,
Int ResourcesId) is loaded into an Animation object. to display the Animation effect, run the startAnimation method of the View to be animated,
Input Animation.
View view = new View (this );
Animation animation = AnimationUtils. loadAnimation (this, R. anim. translate );
View. startAnimation (animation );
Xxx. addView (view );
 
You can also apply the animation effect to the Activity. After the startActivity method is used, the overridePendingTransition method is executed,
The two parameters are the animation effect before the switch, and the animation effect after the switch. OverridePendingTransition only supports android 2.0 and later versions.
StartActivity (intent );


OverridePendingTransition (R. anim. a1, R. anim. a2 );

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.