Animation Type
Android animation consists of four types
In XML
alpha | Gradient transparency animation effect |
scale | Gradient size telescopic animation effect |
translate | Screen conversion position movement animation effect |
rotate | Screen transfer rotation animation effect |
JavaCode
AlphaAnimation | Gradient transparency animation effect |
ScaleAnimation | Gradient size telescopic animation effect |
TranslateAnimation | Screen conversion position movement animation effect |
RotateAnimation | Screen transfer rotation animation effect |
Android animation mode
Animation has two main animation modes:
One is tweened animation (gradual animation)
In XML | JavaCode |
alpha | AlphaAnimation |
scale | ScaleAnimation |
One is frame by frame (screen conversion animation)
In XML | JavaCode |
translate | TranslateAnimation |
rotate | RotateAnimation |
Android animation analysis
alpha xml fade effect
<?xml version="1.0" encoding="utf-8"?> <set xmlns:andro> <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="500" /> </set> <!-- fromAlpha:Transparency at the beginning toAlpha: End transparency duration:Animation duration -->
alpha xml fade effect
<?xml version="1.0" encoding="utf-8"?> <set xmlns:andro> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="500" /> </set> <!-- fromAlpha:Transparency at the beginning toAlpha: End transparency duration:Animation duration -->
Rotate effect:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:andro> <rotate android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromDegrees="300" android:toDegrees="-360" android:pivotX="10%" android:pivotY="100%" android:duration="10000" /> </set> <!-- fromDegrees Angle at the beginning of the animation toDegrees The rotation angle of the object at the end of the animation,Forward means clockwise pivotX The attribute is the animation relative to the objectXThe start position of the coordinates pivotY The attribute is the animation relative to the objectYThe start position of the coordinates -->
Zoom effect:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:andro> <scale android:interpolator= "@android:anim/decelerate_interpolator" android:fromXScale="0.0" android:toXScale="1.5" android:fromYScale="0.0" android:toYScale="1.5" android:pivotX="50%" android:pivotY="50%" android:startOffset="0" android:duration="10000" android:repeatCount="1" android:repeatMode="reverse" /> </set> <!-- fromXDelta,fromYDelta At the beginningX,Ycoordinate,屏幕右下角的coordinate是X:320,Y:480 toXDelta, toYDelta At the end of the animationX,Y的coordinate --> <!-- interpolator Specify an animation inserter Common ones include acceleration and deceleration inserts accelerate_decelerate_interpolator Accelerator inserter accelerate_interpolator, Reducing inserter decelerate_interpolator。 fromXScale,fromYScale, Before the animation beginsX,YZoom of,0.0To not display, 1.0It is normal size toXScale,toYScale, Multiple of the final scaling of the animation, 1.0It is normal size,Greater than1.0enlarge pivotX, pivotY Start position of animation,Percentage relative to screen,Both are50%Indicates that the animation starts from the middle of the screen startOffset, The interval between multiple animation executions,If only once,This period of time will be paused before execution, Unit milliseconds duration,Time spent on an animation effect,Unit milliseconds, The smaller the value, the faster the animation speed repeatCount,Count of animation repetitions,The animation will execute this value+1Second-rate repeatMode,Animation repeating mode,reverseFor reverse,当第偶Second-rate执行时,The animation direction will be opposite。 restartFor re-execution,The direction remains unchanged -->
Move effect:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:andro> <translate android:fromXDelta="320" android:toXDelta="0" android:fromYDelta="480" android:toYDelta="0" android:duration="10000" /> </set> <!-- fromXDelta,fromYDelta At the beginningX,Ycoordinate,屏幕右下角的coordinate是X:320,Y:480 toXDelta, toYDelta At the end of the animationX,Y的coordinate -->
The above article details about Android animation effects translate, scale, alpha, and rotate are all the content I have shared with you. I hope you can give you a reference and I hope you can support me more.