Android Notes (64) animations in Android-motion tweens (tweened animation)

Source: Internet
Author: User

A tweened animation is just where the animation begins and ends, and the changes in the middle of the animation are filled by the system.

Motion tweens are made up of four ways:

1.aplhaanimation--Transparency Animation effect

2.scaleanimation--Zoom Animation effect

3.translateanimation--Displacement Animation effect

4.rotateanimation--Rotate animation effect

1.AplhaAnimation

Parameters of the Aplhaanimation:

Fromalpha: Transparency at the beginning of the animation, 0.0 for full transparency

Toalpha: Transparency at the end of the animation, 1.0 means completely opaque

 PackageCn.lixyz.animator;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.util.Log;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;Importandroid.view.animation.AlphaAnimation;Importandroid.view.animation.Animation;ImportAndroid.view.animation.Animation.AnimationListener;ImportAndroid.widget.Button;ImportAndroid.widget.ImageView; Public classMainactivityextendsActivityImplementsOnclicklistener {PrivateImageView IV; PrivateButton Alpha; Privatealphaanimation alphaanimation; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main);    Initview (); }    Private voidInitview () {IV=(ImageView) Findviewbyid (r.id.image); Alpha=(Button) Findviewbyid (R.id.alpha); Alpha.setonclicklistener ( This); } @Override Public voidOnClick (View v) {Switch(V.getid ()) { Caser.id.alpha:alphaanimation=NewAlphaanimation (0.1f, 1); Alphaanimation.setduration (1000); Alphaanimation.setrepeatcount (3);            Alphaanimation.setrepeatmode (Animation.reverse);            Iv.startanimation (alphaanimation); Alphaanimation.setanimationlistener (NewAnimationlistener () {@Override Public voidOnanimationstart (Animation Animation) {LOG.D ("Tttt", "animation start"); } @Override Public voidonanimationrepeat (Animation Animation) {LOG.D ("Tttt", "animation Repetition"); } @Override Public voidonanimationend (Animation Animation) {LOG.D ("Tttt", "End of animation");            }            });  Break; }    }}

Common Properties:

Setrepeatcount (int repeatcount)--set number of repetitions

Setfillafter (Boolean)--whether the animation stays in the finished state after execution

Setstartoffset (Long Startoffset)--wait time before execution

2.ScaleAnimation

Parameters of the Scakeanimation:

FromX: Scaling dimensions on X-coordinates at start of animation

ToX: Stretch size on x-coordinate at end of animation

FromY: Scaling dimensions on y-coordinates at start of animation

ToY: Stretch size on y-coordinate at end of animation

Pivotxtype: Animation in x-axis relative to object position type

Pivotxvalue: The start position of the animation relative to the x-coordinate of the object

Pivotytype: Animation in Y-axis relative to object position type

Pivotyvalue: The start position of the animation relative to the y-coordinate of the object

 PackageCn.lixyz.animator;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.util.Log;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;Importandroid.view.animation.Animation;Importandroid.view.animation.ScaleAnimation;ImportAndroid.widget.Button;ImportAndroid.widget.ImageView; Public classMainactivityextendsActivityImplementsOnclicklistener {PrivateImageView IV; PrivateButton Scale; Privatescaleanimation scaleanimation; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main);    Initview (); }    Private voidInitview () {IV=(ImageView) Findviewbyid (r.id.image); Scale=(Button) Findviewbyid (R.id.scale); Scale.setonclicklistener ( This); } @Override Public voidOnClick (View v) {Switch(V.getid ()) { CaseR.id.scale:scaleanimation=NewScaleanimation (0.0f, 1.4f, 0.0f, 1.4f, Animation.relative_to_self, 0.5f, Animation.relative_to_self,0.5f); Scaleanimation.setduration (3000);            Iv.startanimation (scaleanimation);  Break; }    }}

Common Properties:

Setrepeatcount (int repeatcount)--set number of repetitions

Setfillafter (Boolean)--whether the animation stays in the finished state after execution

Setstartoffset (Long Startoffset)--wait time before execution

3.TranslateAnimation

Parameters of the Translateanimation

Fromxdelta: The difference between the point at which the animation starts and the current view X coordinate

Toxdelta: The difference between the point at which the animation ends and the current view X coordinate

Fromydelta: The difference between the starting point of the animation and the current view y-coordinate

Toydelta the difference between the starting point of the animation and the current view y-coordinate

 PackageCn.lixyz.animator;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;Importandroid.view.animation.TranslateAnimation;ImportAndroid.widget.Button;ImportAndroid.widget.ImageView; Public classMainactivityextendsActivityImplementsOnclicklistener {PrivateImageView IV; PrivateButton Transla; Privatetranslateanimation translaanimation; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main);    Initview (); }    Private voidInitview () {IV=(ImageView) Findviewbyid (r.id.image); Transla=(Button) Findviewbyid (R.id.transla); Transla.setonclicklistener ( This); } @Override Public voidOnClick (View v) {Switch(V.getid ()) { Caser.id.transla:translaanimation=NewTranslateanimation (0, 150, 0, 0); Translaanimation.setduration (1000);            Iv.startanimation (translaanimation);  Break; }    }}

Common Properties:

Animation.setduration (Long Durationmillis)--Set the duration of the animation
Animation.setrepeatcount (int i)--set number of repetitions
Animation.setrepeatmode (Animation.reverse)--Set reverse direction execution

4.RotateAnimation

Parameters of the Rotateanimation:

fromdegrees--the starting angle of the rotation.

todegrees--the end angle of the rotation.

Pivotxtype--x axis of the scaling mode, you can take the value of absolute, relative_to_self, relative_to_parent.

The scaling value of the pivotxvalue--x coordinates.

Pivotytype--y axis of the scaling mode, you can take the value of absolute, relative_to_self, relative_to_parent.

The scaling value of the pivotyvalue--y coordinates.

 PackageCn.lixyz.animator;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;Importandroid.view.animation.Animation;Importandroid.view.animation.RotateAnimation;ImportAndroid.widget.Button;ImportAndroid.widget.ImageView; Public classMainactivityextendsActivityImplementsOnclicklistener {PrivateImageView IV; PrivateButton rotate; Privaterotateanimation rotateanimation; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main);    Initview (); }    Private voidInitview () {IV=(ImageView) Findviewbyid (r.id.image); Rotate=(Button) Findviewbyid (r.id.rotate); Rotate.setonclicklistener ( This); } @Override Public voidOnClick (View v) {Switch(V.getid ()) { Caser.id.rotate:rotateanimation=NewRotateanimation (0, Animation.relative_to_self, 0.5f, Animation.relative_to_self,0.5f); Rotateanimation.setduration (2000);            Iv.startanimation (rotateanimation);  Break; }    }}

Common methods:

Animation.setrepeatcount (int repeatcount)--set number of repetitions
Animation.setfillafter (Boolean)--whether the animation stays in the finished state after execution
Animation.setstartoffset (Longstartoffset)--wait time before execution

Android Notes (64) animations in Android-motion tweens (tweened animation)

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.