Android Animation's translateanimation application detailed

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.