Animation animation effect of two implementation methodsNote: This example is alphaanimation effect, as for other effects, change the object. 1. Java file Code Control Add and start animation animation
Add animation effect Alphaanimation animation = new Alphaanimation (0.3f, 1.0f);//Set the duration of the secondary Effect Animation.setduration (2000);// Sets the listener event for the animation Animation.setanimationlistener (new Animationlistener () {@Overridepublic void Onanimationstart (Animation Animation) {//Animation start listener event//do something ...} @Overridepublic void Onanimationrepeat (Animation Animation) {} @Overridepublic void Onanimationend (Animation Animation {//Animation end Listener event//do something ...}}); /Start animation view.startanimation (animation);
2.. xml file code load XML start animation Alpha_out.xml fade out effect
<?xml version= "1.0" encoding= "Utf-8"?><!--android:duration= "@android: Integer/config_mediumanimtime"-- ><set xmlns:android= "http://schemas.android.com/apk/res/android" ><alpha android:fromalpha= "1.0" Android:toalpha= "0" android:duration= "$"/> <!--transparency Control animation effect Alpha floating-point value: The Fromalpha property is the transparency at the beginning of the animation The Toalpha property is the transparency description at the end of the animation : 0.0 indicates full transparency 1.0 represents a full opacity above the value of the float data type between 0.0-1.0 and a numeric long integer value: The Duration property is an animation duration Description: The time is in milliseconds--></set>
Code load XML:
Property:
Private Animation anim;private Animationlistener Animlis;
Load:
Initialize the animation listener event Animationlisteneranimlis = new Animationlistener () {@Overridepublic void Onanimationstart (Animation arg0) { The animation starts to listen for events//do something ...} @Overridepublic void Onanimationrepeat (Animation arg0) {} @Overridepublic void Onanimationend (Animation arg0) {// Animation End Listener Event//do something...tv.setvisibility (view.gone);}};/ /Load Xmlanim = Animationutils.loadanimation (this, r.anim.alpha_out);//Set Listener event Anim.setanimationlistener (animLis);// Start animation tv.startanimation (Anim);
Two ways to implement Android animation animation effects