Android animation effects: translate, scale, alpha, and rotate

Source: Internet
Author: User

Animation type

Android animation consists of four types

In XML
Alpha gradient transparency animation effect
Scale scaling Animation
Animated effect of moving the translate position
Rotate screen transfer rotation animation effect


Java code
AlphaAnimation gradient transparency animation effect
ScaleAnimation gradient scaling animation effect
TranslateAnimation
RotateAnimation image transfer rotation animation effect

Android Animation Mode

Animation mainly has two Animation modes:

One is tweened animation (gradient animation)
Java code in XML
Alpha AlphaAnimation
Scale ScaleAnimation


One is frame by frame (screen conversion animation)

Java code in XML
Translate TranslateAnimation
Rotate RotateAnimation

 

Android animation Parsing


Alpha xml fade-out effect

 

 

[Cpp]
<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android">
<Alpha
Android: fromalphi = "1.0"
Android: toAlpha = "0.0"
Android: duration = "500"/>
</Set>
<! --
FromAlpha: transparency at the beginning
ToAlpha: transparency at end
Duration: animation duration -->
[Cpp]
<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android">
<Alpha
Android: fromalphi = "1.0"
Android: toAlpha = "0.0"
Android: duration = "500"/>
</Set>
<! --
FromAlpha: transparency at the beginning
ToAlpha: transparency at end
Duration: animation duration -->

<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android">
<Alpha
Android: fromalphi = "1.0"
Android: toAlpha = "0.0"
Android: duration = "500"/>
</Set>
<! --
FromAlpha: transparency at the beginning
ToAlpha: transparency at end
Duration: animation duration -->


Alpha xml fade-in effect


[Cpp]
<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android">
<Alpha
Android: fromalphi = "0.0"
Android: toAlpha = "1.0"
Android: duration = "500"/>
</Set>
<! --
FromAlpha: transparency at the beginning
ToAlpha: transparency at end
Duration: animation duration -->
[Cpp]
<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android">
<Alpha
Android: fromalphi = "0.0"
Android: toAlpha = "1.0"
Android: duration = "500"/>
</Set>
<! --
FromAlpha: transparency at the beginning
ToAlpha: transparency at end
Duration: animation duration -->

<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android">
<Alpha
Android: fromalphi = "0.0"
Android: toAlpha = "1.0"
Android: duration = "500"/>
</Set>
<! --
FromAlpha: transparency at the beginning
ToAlpha: transparency at end
Duration: animation duration -->

 

Rotate. xml rotation effect:
[Html]
<? Xmlversion = "1.0" encoding = "UTF-8"?>
<Setxmlns: android = "http://schemas.android.com/apk/res/android">
<Rotate
Android: interpolator = "@ android: anim/accelerate_decelerate_interpolator"
Android: fromDegrees = "300"
Android: toDegrees = "-360"
Android: Required Tx = "10%"
Android: Ty = "100%"
Android: duration = "10000"/>
</Set>
<! --
FromDegrees animation start angle
The Rotation Angle of the object at the end of the toDegrees animation, representing clockwise
The ready TX attribute is the starting position of the animation relative to the X coordinate of the object.
The Ty attribute is the starting position of the animation relative to the Y coordinate of the object -->
[Html] view plaincopyprint?
<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android">
<Rotate
Android: interpolator = "@ android: anim/accelerate_decelerate_interpolator"
Android: fromDegrees = "300"
Android: toDegrees = "-360"
Android: Required Tx = "10%"
Android: Ty = "100%"
Android: duration = "10000"/>
</Set>
<! --
FromDegrees animation start angle
The Rotation Angle of the object at the end of the toDegrees animation, representing clockwise
The ready TX attribute is the starting position of the animation relative to the X coordinate of the object.
The Ty attribute is the starting position of the animation relative to the Y coordinate of the object -->

<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android">
<Rotate
Android: interpolator = "@ android: anim/accelerate_decelerate_interpolator"
Android: fromDegrees = "300"
Android: toDegrees = "-360"
Android: Required Tx = "10%"
Android: Ty = "100%"
Android: duration = "10000"/>
</Set>
<! --
FromDegrees animation start angle
The Rotation Angle of the object at the end of the toDegrees animation, representing clockwise
The ready TX attribute is the starting position of the animation relative to the X coordinate of the object.
The Ty attribute is the starting position of the animation relative to the Y coordinate of the object -->


Scale. xml Scaling:


[Cpp]
<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android">
<Scale
Android: interpolator = "@ android: anim/decelerate_interpolator"
Android: fromXScale = "0.0"
Android: toXScale = "1.5"
Android: fromYScale = "0.0"
Android: toYScale = "1.5"
Android: Required Tx = "50%"
Android: Ty = "50%"
Android: startOffset = "0"
Android: duration= "10000"
Android: repeatCount = "1"
Android: repeatMode = "reverse"/>
</Set>

<! --
FromXDelta, fromYDelta start with X, Y coordinates, the coordinates in the lower right corner of the screen are X: 320, Y: 480
Coordinates of X and Y at the end of toXDelta and toYDelta animation --> <! --
Interpolator specifies the animation insertor
Common acceleration and deceleration inserts are accelerate_decelerate_interpolator.
Accelerate_interpolator,
Decelerate_interpolator.
FromXScale and fromYScale: Scale X and Y before the animation starts. If 0.0 is not displayed, 1.0 is normal.
ToXScale, toYScale, the final scaling multiple of the animation, 1.0 is the normal size, greater than 1.0 to zoom in
Starting position of the animated TX or Ty animation, both of which are 50% relative to the screen percentage, indicates that the animation starts from the center of the screen.
StartOffset: Specifies the interval between multiple animation executions. If an animation is executed only once, it is paused before execution,
The Unit is millisecond duration. The time consumed by an animation. The unit is millisecond,
The smaller the value, the faster the animation speed, the more repeatCount, the animation repeats the count, the animation will execute this value + 1
RepeatMode: Specifies the animation repetition mode. The reverse indicates the reverse direction. When the animation is executed for the first time, the animation is in the opposite direction.
Restart is re-executed, and the direction remains unchanged -->
[Cpp]
<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android">
<Scale
Android: interpolator = "@ android: anim/decelerate_interpolator"
Android: fromXScale = "0.0"
Android: toXScale = "1.5"
Android: fromYScale = "0.0"
Android: toYScale = "1.5"
Android: Required Tx = "50%"
Android: Ty = "50%"
Android: startOffset = "0"
Android: duration= "10000"
Android: repeatCount = "1"
Android: repeatMode = "reverse"/>
</Set>
 
<! --
FromXDelta, fromYDelta start with X, Y coordinates, the coordinates in the lower right corner of the screen are X: 320, Y: 480
Coordinates of X and Y at the end of toXDelta and toYDelta animation --> <! --
Interpolator specifies the animation insertor
Common acceleration and deceleration inserts are accelerate_decelerate_interpolator.
Accelerate_interpolator,
Decelerate_interpolator.
FromXScale and fromYScale: Scale X and Y before the animation starts. If 0.0 is not displayed, 1.0 is normal.
ToXScale, toYScale, the final scaling multiple of the animation, 1.0 is the normal size, greater than 1.0 to zoom in
Starting position of the animated TX or Ty animation, both of which are 50% relative to the screen percentage, indicates that the animation starts from the center of the screen.
StartOffset: Specifies the interval between multiple animation executions. If an animation is executed only once, it is paused before execution,
The Unit is millisecond duration. The time consumed by an animation. The unit is millisecond,
The smaller the value, the faster the animation speed, the more repeatCount, the animation repeats the count, the animation will execute this value + 1
RepeatMode: Specifies the animation repetition mode. The reverse indicates the reverse direction. When the animation is executed for the first time, the animation is in the opposite direction.
Restart is re-executed, and the direction remains unchanged -->

<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android">
<Scale
Android: interpolator = "@ android: anim/decelerate_interpolator"
Android: fromXScale = "0.0"
Android: toXScale = "1.5"
Android: fromYScale = "0.0"
Android: toYScale = "1.5"
Android: Required Tx = "50%"
Android: Ty = "50%"
Android: startOffset = "0"
Android: duration= "10000"
Android: repeatCount = "1"
Android: repeatMode = "reverse"/>
</Set>

<! --
FromXDelta, fromYDelta start with X, Y coordinates, the coordinates in the lower right corner of the screen are X: 320, Y: 480
Coordinates of X and Y at the end of toXDelta and toYDelta animation --> <! --
Interpolator specifies the animation insertor
Common acceleration and deceleration inserts are accelerate_decelerate_interpolator.
Accelerate_interpolator,
Decelerate_interpolator.
FromXScale and fromYScale: Scale X and Y before the animation starts. If 0.0 is not displayed, 1.0 is normal.
ToXScale, toYScale, the final scaling multiple of the animation, 1.0 is the normal size, greater than 1.0 to zoom in
Starting position of the animated TX or Ty animation, both of which are 50% relative to the screen percentage, indicates that the animation starts from the center of the screen.
StartOffset: Specifies the interval between multiple animation executions. If an animation is executed only once, it is paused before execution,
The Unit is millisecond duration. The time consumed by an animation. The unit is millisecond,
The smaller the value, the faster the animation speed, the more repeatCount, the animation repeats the count, the animation will execute this value + 1
RepeatMode: Specifies the animation repetition mode. The reverse indicates the reverse direction. When the animation is executed for the first time, the animation is in the opposite direction.
Restart is re-executed, and the direction remains unchanged -->

 

 

Translate. xml:
[Html]
<? Xmlversion = "1.0" encoding = "UTF-8"?>
<Setxmlns: android = "http://schemas.android.com/apk/res/android">
<Translate
Android: fromxdel= "320"
Android: toXDelta = "0"
Android: fromYDelta = "480"
Android: toYDelta = "0"
Android: duration = "10000"/>
</Set>
<! --
FromXDelta, fromYDelta start with X, Y coordinates, the coordinates in the lower right corner of the screen are X: 320, Y: 480
Coordinates of X and Y at the end of toXDelta and toYDelta animation -->
[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android">
<Translate
Android: fromxdel= "320"
Android: toXDelta = "0"
Android: fromYDelta = "480"
Android: toYDelta = "0"
Android: duration = "10000"/>
</Set>
<! --
FromXDelta, fromYDelta start with X, Y coordinates, the coordinates in the lower right corner of the screen are X: 320, Y: 480
Coordinates of X and Y at the end of toXDelta and toYDelta animation -->

<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android">
<Translate
Android: fromxdel= "320"
Android: toXDelta = "0"
Android: fromYDelta = "480"
Android: toYDelta = "0"
Android: duration = "10000"/>
</Set>
<! --
FromXDelta, fromYDelta start with X, Y coordinates, the coordinates in the lower right corner of the screen are X: 320, Y: 480
Coordinates of X and Y at the end of toXDelta and toYDelta animation -->

 

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.