Translateanimation animation, translateanimation more commonly used, such as QQ, NetEase news menu bar animation, you can use the translateanimation to achieve,
Define animations with translateanimation (float fromxdelta, float toxdelta, float fromydelta, float toydelta)
Parameter description:
The code is as follows:
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:
The code is as follows:
Animation.setduration (long Durationmillis);//Set animation duration
Animation.setrepeatcount (int i);//Set the number of repetitions
Animation.setrepeatmode (animation.reverse);//Set Reverse direction execution
XML attributes:
The code is as follows:
Android:duration: Time to run the animation
Android:repeatcount: Defines when the animation repeats
Code:
The code is as follows:
public class Mainactivity extends Activity {
ImageView image;
Button start;
Button Cancel;
@Override
public void OnCreate (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 shift right 150 */
Final Translateanimation animation = new Translateanimation (0, 150, 0, 0);
Animation.setduration (2000);//Set animation duration
Animation.setrepeatcount (2);//Set Number of repetitions-1 means to keep circulating
Animation.setrepeatmode (animation.reverse);//Set Reverse direction execution
Start.setonclicklistener (New Onclicklistener () {
public void OnClick (View arg0) {
Image.setanimation (animation);
/** Start Animation */
Animation.startnow ();
}
});
Cancel.setonclicklistener (New Onclicklistener () {
public void OnClick (View v) {
/** End Animation */
Animation.cancel ();
}
});
}
}
Android Animation's translateanimation application detailed