Android Animation scaleanimation Application Specific explanation

Source: Internet
Author: User

4 animations are available in Android: Alphaanimation transparency animation effect Scaleanimation Zoom animation effect Translateanimation Displacement animation effect rotateanimation rotate animation effect This section explains Scaleanimation animations, scaleanimation (float FromX, float toX, float fromY, float toy,int pivotxtype, float pivotxvalue, in T Pivotytype, float pivotyvalue) parameter description: Copy code code such as the following: float FromX the scaling dimension on x-coordinate at the start of the animation float ToX the scaling dimension at the end of the animation at the x-coordinate float FromY when the animation starts Scaling dimensions on the y-coordinate float toY The stretch dimensions on the y-coordinate of the animation at the end of the int pivotxtype animation in the x-axis relative to the object position type float Pivotxvalue animation relative to the object's x-coordinate start position int Pivotytype animation in y-axis relative For object position type float pivotyvalue The start position code of the animation relative to the object's Y coordinate: Copy code code such as the following: public class Mainactivity extends Activity {ImageView image; B Utton 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); /** Setting the Zoom animation */FINAL scaleanimation animation =new scaleanimation (0.0f, 1.4f, 0.0f, 1.4f, ANimation. Relative_to_self, 0.5f, Animation.relative_to_self, 0.5f); Animation.setduration (2000);//Set animation duration/** Regular usage *///animation.setrepeatcount (int repeatcount);//Set repeat times// Animation.setfillafter (Boolean);//Whether the animation stays in the running state after running//animation.setstartoffset (long startoffset);//wait time before running 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 ();}}); } }
This section explains Scaleanimation animations, scaleanimation (float FromX, float toX, float fromY, float toy,int pivotxtype, float pivotxvalue, in T Pivotytype, float pivotyvalue) parameter description: Copy code code such as the following: float FromX the scaling dimension on x-coordinate at the start of the animation float ToX the scaling dimension at the end of the animation at the x-coordinate float FromY when the animation starts Scaling dimensions on the y-coordinate float toY The stretch dimensions on the y-coordinate of the animation at the end of the int pivotxtype animation in the x-axis relative to the object position type float Pivotxvalue animation relative to the object's x-coordinate start position int Pivotytype animation in y-axis relative For object position type float pivotyvalue The start position code of the animation relative to the object's Y coordinate: Copy code code such as the following: public class Mainactivity extends Activity {ImageView image; B Utton 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 Zoom animation */FINAL scaleanimation animation =new scaleanimation (0.0f, 1.4f, 0.0f, 1.4f, Animation.relative_to_self, 0.5f, Animation.relative_to_self, 0.5f); Animation.setduration (2000);//Set animation duration/**Regular usage *///animation.setrepeatcount (int repeatcount);//Set repeated//animation.setfillafter (Boolean);//Whether the animation remains in the running state after it has run out Animation.setstartoffset (long Startoffset);//wait time before run 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 ();}}); } }
This section explains Rotateanimation animations, rotateanimation (float fromdegrees, float todegrees, int pivotxtype, float pivotxvalue, int pivoty Type, float pivotyvalue) parameter description: Float fromdegrees: Start angle of rotation. Float todegrees: The end angle of the rotation. int pivotxtype:x The scaling mode of the axis, can take the value of absolute, relative_to_self, relative_to_parent. The scaling value of the float pivotxvalue:x coordinates. int Pivotytype:y The scaling mode of the axis, can take the value of absolute, relative_to_self, relative_to_parent. The scaling value of the float pivotyvalue:y coordinates. Code:Copy Code Code such as the following: 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 Rotation animation */FINAL rotateanimation animation =new rotateanimation (0f,360f,animation.relative_to_self, 0.5f, animation.relative_to_self,0.5f); Animation.setduration (3000);//Set animation duration/** Regular usage *///animation.setrepeatcount (int repeatcount);//Set repeat times// Animation.setfillafter (Boolean);//Whether the animation stays in the running state after running//animation.setstartoffset (long startoffset);//wait time before running 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 (); } });  } }
This section explains Translateanimation animation, translateanimation is often used, such as QQ, NetEase news menu bar animation, can be implemented with Translateanimation, The description of the animation parameters is defined by translateanimation (float Fromxdelta, float toxdelta, float fromydelta, float Toydelta):Copy CodeThe code for example is the following: float Fromxdelta the difference from the current view x-coordinate between the start point of the animation, float Toxdelta The difference between the end of the animation and the current view x-coordinate, float fromydelta the difference from the current view y-coordinate of the animation start point Float Toydelta The difference between the starting point of the animation from the current view y-coordinate is often used:Copy CodeThe code for example is the following: Animation.setduration (long Durationmillis);//Set animation duration animation.setrepeatcount (int i);//Set repetition times Animation.setrepeatmode (animation.reverse);//Set the XML property to run in the opposite direction:Copy CodeCode such as the following: Android:duration: Time to perform animation Android:repeatcount: Defines the time code for the animation to repeat:Copy Code Code such as the following: 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 to the right of the offset */FINAL translateanimation animation = new Translateanimation (0, 150, 0, 0); Animation.setduration (2000);//Set Animation duration Animation.setrepeatcount (2);//Set repeat times Animation.setrepeatmode ( Animation.reverse);//Set the opposite direction to run 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 ();}}); }}     
This section explains Alphaanimation animations, forms of animation effects, fades and fades, some of the game's welcome animation, the logo fade effect on the use of alphaanimation. Look directly at the code: Copy code code such as the following: 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 Transparency Gradient animation */FINAL alphaanimation animation = new Alphaanimation (1, 0); Animation.setduration (2000);//Set animation duration/** Regular usage *///animation.setrepeatcount (int repeatcount);//Set repeat times// Animation.setfillafter (Boolean);//Whether the animation stays in the running state after running//animation.setstartoffset (long startoffset);//wait time before running 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) {/** endAnimation */Animation.cancel (); } }); } }

Android Animation scaleanimation Application Specific explanation

Related Article

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.