Translateanimation more commonly used, such as QQ, NetEase news menu bar animation, you can use translateanimation to achieve,
Define animations with translateanimation (float fromxdelta, float toxdelta, float fromydelta, float toydelta)
Parameter description:
Float Fromxdelta The difference from the current view x-coordinate of the starting point of the animation
Float Toxdelta The difference in the end of the animation from the current view x-coordinate
Float Fromydelta The difference between the starting point of the animation and the current view y-coordinate
Float Toydelta The difference between the starting point of the animation and the current view y-coordinate
Common methods:
animation.setduration (long durationmillis); // animation.setrepeatcount (int i); // Animation.setrepeatmode (animation.reverse); //
Code:
Public classMainactivityextendsActivity {ImageView image; Button start; Button Cancel; @Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (r.layout.activity_main); Image=(ImageView) Findviewbyid (r.id.main_img); start=(Button) Findviewbyid (R.id.main_start); Cancel=(Button) Findviewbyid (r.id.main_cancel);/**set displacement animation to shift to the right*/ Finaltranslateanimation animation =NewTranslateanimation (0, 150, 0, 0); Animation.setduration (2000);//set the duration of an animationAnimation.setrepeatcount (2);//set number of repetitionsAnimation.setrepeatmode (Animation.reverse);//set the reverse direction of executionStart.setonclicklistener (NewOnclicklistener () { Public voidOnClick (View arg0) {image.setanimation (animation);/**Start Animation*/Animation.startnow ();} }); Cancel.setonclicklistener (NewOnclicklistener () { Public voidOnClick (View v) {/**End Animation*/animation.cancel ();} }); } }
Android Animation's translateanimation application detailed