1.Android Animation mode:
1>tweened Animation: Gradient animation;
2>frame by frame: Picture conversion animation.
The 2.Android animation animation consists of four types:
Xml
|
Alpha |
Gradient Transparency Animation effect |
Scale |
Gradient Dimension Stretch animation effect |
Translate |
Move animation effect on picture transition position |
Rotate |
Picture Transfer rotation animation effect |
Java code
|
Alphaanimation |
Gradient Transparency Animation effect |
Scaleanimation |
Gradient Dimension Stretch animation effect |
Translateanimation |
Move animation effect on picture transition position |
Rotateanimation |
Picture Transfer rotation animation effect |
3. Animation effect Example
Under res/create a new Anim folder, the following animation file into Anim below
1> Alpha fade-in effect:
<?xml version= "1.0" encoding= "Utf-8"?> <set xmlns:android= "Http://schemas.android.com/apk/res/android" > <alpha android:fromalpha= "0.0" android:toalpha= "1.0" android:duration= "$"/> </set> <!--fromalpha: Transparency Toalpha at the beginning: Transparency at the end duration: Duration of animation--
2>Alpha fade out effect:
<?xml version= "1.0" encoding= "Utf-8"?> <set xmlns:android= "Http://schemas.android.com/apk/res/android" > <alpha android:fromalpha= "1.0" android:toalpha= "0.0" android:duration= "$"/> </set> <!--fromalpha: Transparency Toalpha at the beginning: Transparency at the end duration: Duration of animation--
3> Rotate rotation effect:
<?xml version= "1.0" encoding= "Utf-8"? > <set xmlns:android= "Http://schemas.android.com/apk/res/android" android:fillafter= "false" android:zadjustment= "Bottom" > <rotate android:duration= "4000" android:fromdegrees= "0" android:pivotx= "50%" android: Pivoty= "50%" android:todegrees= "360" /> <!-- fromdegrees the angle at which the animation starts todegrees the rotation angle of the object at the end of the animation, which means clockwise The pivotX property is the start position of the animation relative to the X coordinate of the object pivotY property is the start position of the animation relative to the y-coordinate of the object --> </set>
4> Scale Scaling effect:
<?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:pivotx= "50%" android:pivoty= "50%" android:repeatcount= "1" android:repeaTmode= "reverse" android:startoffset= "0" android:toxscale= "1.5" android:toyscale= "1.5" /> </set> <!-- fromxdelta,fromydelta at the beginning of the x, y coordinates, the lower right corner of the screen is the coordinates x:320,y:480 toXDelta, toYDelta coordinates of x, y at the end of the animation --> <!-- interpolator Specifies the animation insert, a common acceleration reducer:accelerate_decelerate_interpolator speed up the insertion device accelerate_interpolator, decelerate The decelerate_interpolator of the insertion device. fromXScale,fromYScale, x, y zoom before animation starts, 0.0 is not displayed, 1.0 is normal size toXScale,toYScale, the multiple of the final zoom of the animation, 1.0 to normal size, greater than 1.0 magnification pivotX, pivotY The starting position of the animation, relative to the percentage of the screen, two of which are 50% means the animation starts from the middle of the screen startOffset, the interval of time when the animation is executed more than once, which pauses the time before execution, Unit millisecond duration, the time the animation effect consumes, the smaller the, value of the unit milliseconds the faster the animation repeatcount , the animation repeats the count, the animation will execute the value + 1 times repeatmode, the animation repeats the pattern, the reverse is reversed, When an even execution occurs, the animation will be in the opposite direction. &nbSp;restart for re-execution, direction invariant -->
5> translate Move effect:
<?xml version= "1.0" encoding= "Utf-8"? > <set xmlns:android= "http ://schemas.android.com/apk/res/android " > <translate android:duration= "4000" android:fromxdelta= "0" android:fromydelta= "0" android:toxdelta= " " android:toydelta= "0" /> </set> <!-- fromXDelta,fromYDelta initial x, y coordinates, The coordinates in the lower right corner of the screen are x:320,y:480 toxdelta, toydelta x, y coordinates at the end of the animation -->
To reference an animation file in your code:
public class mainactivity extends activity implements Android.view.view.onclicklistener {private textview tvshow;private button btnrotate, btnfadeout,btnfadein,btnscale,btntranslate;private animation animation = null; @Override protected void oncreate (bundle savedinstancestate) { super.oncreate (savedinstancestate); requestwindowfeature (Window.feature_no_title); setcontentview (R.layout.activity_main); tvshow = (TextView) findviewbyid (r.id.tvshow); btnrotate = (Button) findviewbyid (r.id.btnrotate); btnrotate.setonclicklistener (this); btnfadeout = (Button) findviewbyid (R.id.btnFadeOut); btnfadeout.setonclicklistener (This); btnFadeIn = (Button) findviewbyid (R.id.btnfadein); btnfadein.setonclicklistener (This); btnscale = (Button) findviewbyid (R.id.btnscale); btnscale.setonclicklistener (this); btntranslate = (Button) findviewbyid (r.id.btntranslate); Btntranslate.setonclicklistener (This); } @Override public void onclick (view v) { switch (V.getid ()) { //Flip case r.id.btnrotate:animation = Animationutils.loadanimation (this, r.anim.rotate); break; / /Fade Out case r.id.btnfadeout:animation = animationutils.loadanimation (This, R.anim.alpha_ fadeout); break;//fade in Case r.id.btnfadein:animation = animationutils.loadanimation (this, R.anim.alpha_fadein); break;//Zoom Case r.id.btnscale:animation = animationutils.loadanimation (This , r.anim.scale); break;//Pan case r.id.btntranslate:animation = animationutils.loadanimation ( this, r.anim.translate); break;default:break;} if (animation != null) { tvshow.startanimation ( animation); } }}
See the results:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/76/86/wKioL1ZVb2-D9VeAAAOX8SNsDq8456.gif "title=" Gif.gif "alt=" Wkiol1zvb2-d9veaaaox8snsdq8456.gif "/>
This article is from the "alan_y (upspringing)" blog, so be sure to keep this source http://alany.blog.51cto.com/6125308/1716795
Android Learning--animation animation effects