Custom animation effects
Create a new Customanim class
1 Packagecom.liwenchi.myapplication;2 3 Importandroid.view.animation.Animation;4 Importandroid.view.animation.Transformation;5 6 Import Staticjava.lang.math.*;7 8 /**9 * Created by VULCAN on 2017/8/2.Ten */ One A Public classCustomanimextendsAnimation { - - @Override the protected voidApplytransformation (floatInterpolatedtime, Transformation t) { - //Interpolatedtime represents the time of the tween animation, starting with the 0~1,0 delegate, 1 representing the end - //T stands for changing objects - floatp =Interpolatedtime; + Super. Applytransformation (Interpolatedtime, t); - //System.out.println (interpolatedtime); + //T.setalpha (interpolatedtime); set transparency A //T.getmatrix (). Settranslate (0, -300*p); Set Location atT.getmatrix (). Settranslate ((float) (Sin (p*2*6.28*p) *50), 0); - } -}
Where, overriding the Applytransformation () method
Create a Customanim animation in Mainactivity.java
1 Packagecom.liwenchi.myapplication;2 3 Importandroid.support.v7.app.AppCompatActivity;4 ImportAndroid.os.Bundle;5 ImportAndroid.view.View;6 Importandroid.view.animation.AlphaAnimation;7 Importandroid.view.animation.Animation;8 ImportAndroid.view.animation.AnimationSet;9 Importandroid.view.animation.AnimationUtils;Ten Importandroid.view.animation.RotateAnimation; One Importandroid.view.animation.ScaleAnimation; A Importandroid.view.animation.TranslateAnimation; - ImportAndroid.widget.Button; - ImportAndroid.widget.CheckBox; the ImportAndroid.widget.CompoundButton; - ImportAndroid.widget.TextView; - - Public classMainactivityextendsappcompatactivity { + - PrivateCustomanim CA; + A @Override at protected voidonCreate (Bundle savedinstancestate) { - Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); - slove (); - } - in Private voidSlove () { -CA =NewCustomanim (); toCa.setduration (1000); +Findviewbyid (R.ID.BTN). Setonclicklistener (NewView.onclicklistener () { - the @Override * Public voidOnClick (View v) { $ V.startanimation (CA);Panax Notoginseng } - }); the } + } A //v.startanimation (Animationutils.loadanimation (Mainactivity.this, R.anim.ta));
This allows you to customize a "shake" animation effect
[2017-8-2] Android Learning Day8