Android (v) Animation animation

Source: Internet
Author: User

The first type: code format:

 Packagecom.itzb.annimation;ImportAndroid.os.Bundle;Importandroid.app.Activity;ImportAndroid.view.Menu;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;Importandroid.view.animation.AlphaAnimation;Importandroid.view.animation.Animation;ImportAndroid.view.animation.AnimationSet;Importandroid.view.animation.RotateAnimation;Importandroid.view.animation.ScaleAnimation;Importandroid.view.animation.TranslateAnimation;ImportAndroid.widget.Button;Importandroid.widget.LinearLayout;ImportAndroid.widget.Toast; Public classMainactivityextendsActivityImplementsOnclicklistener {PrivateButton Btnxz; PrivateButton btnsf; PrivateButton BTNRC; PrivateButton btnpy; PrivateLinearLayout ll; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); Btnxz=(Button) Findviewbyid (R.ID.BTNXZ); Btnsf=(Button) Findviewbyid (R.ID.BTNSF); BTNRC=(Button) Findviewbyid (R.ID.BTNRC); Btnpy=(Button) Findviewbyid (r.id.btnyd); ll=(LinearLayout) Findviewbyid (R.ID.LL); Btnxz.setonclicklistener ( This); Btnsf.setonclicklistener ( This); Btnrc.setonclicklistener ( This); Btnpy.setonclicklistener ( This); } @Override Public BooleanOncreateoptionsmenu (Menu menu) {//inflate the menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (R.menu.main, menu); return true; } @Override Public voidOnClick (View v) {intID =V.getid (); if(id = =Btnxz.getid ())        {rotaanimationshow (); } Else if(id = =Btnsf.getid ())        {scalanimationshow (); } Else if(id = =Btnrc.getid ())        {alphaanimationshow (); } Else if(id = =Btnpy.getid ())        {translateanimationshow (); }    }    //gradually into the gradual draw     Public voidalphaanimationshow () {alphaanimation AA=NewAlphaanimation (0.1f, 1.0f);//parameter representation, transparency from 0.1 to 1Aa.setduration (3000);//sets the animation time. Aa.setfillafter (true);//sets the result status. Do not set the line. Ll.startanimation (AA);//Start Animation//where the first parameter of the Alphaanimation class Fromalpha represents the transparency at the beginning of the animation, the second parameter Toalpha represents the transparency at the end of the animation.     }    //Rotate Animation     Public voidrotaanimationshow () {//where the first parameter of the Rotateanimation class Fromdegrees represents the angle at which the animation starts,//the second parameter, Todegrees, represents the angle at the end of the animation.        The third fourth represents a center point rotation. //In addition, you can set the scaling mode Pivotxtype, Pivotytype, scaling animation relative to X, y//coordinates start at Pivotxvalue, Pivotyvalue, and so on. Rotateanimation AA =Newrotateanimation (0f, 360f, Animation.relative_to_self,0.5f, Animation.relative_to_self,0.5f); Aa.setduration (3000); Ll.startanimation (AA);//Start Animation    }    //Zoom Animation     Public voidscalanimationshow () {/** The first parameter is FROMX, and the second parameter is Tox: The scaling dimension on the x-coordinate at the beginning and end of the animation, respectively. The third parameter is fromy *, and the fourth parameter toy: The scaling dimension on the y-coordinate of the start and end of the animation, respectively. You can also add anchor points, animation.relative_to_self, * 0.5f, Animation.relative_to_self, 0.5f * In addition, you can also set the scaling mode Pivotxtype, pivot         YType, the scaling animation is relative to the start position of x, y * coordinates pivotxvalue, pivotyvalue, and so on. */scaleanimation SA=NewScaleanimation (0.1f, 1.0f, 0.1f, 1.0f); Sa.setduration (3000);    Ll.startanimation (SA); }    //Displacement Animation     Public voidtranslateanimationshow () {/** The first parameter is Fromxdelta, and the second parameter is Toxdelta: The x-coordinate of the start and end of the animation, respectively.         The third parameter Fromydelta *, the fourth parameter Toydelta: The start of the animation, the end of the y-coordinate. */translateanimation ta=NewTranslateanimation (0.1f, 100.0f, 0.1f,                100.0f); Ta.setduration (3000);    Ll.startanimation (TA); }    //Animation Set     Public voidanimationsetshow () {alphaanimation AA=NewAlphaanimation (0.1f, 1.0f);//parameter representation, transparency from 0.1 to 1Aa.setduration (3000);//sets the animation time. Rotateanimation RA =Newrotateanimation (0f, 360f, Animation.relative_to_self,0.5f, Animation.relative_to_self,0.5f); Animationset as=NewAnimationset (true);        As.addanimation (AA);        As.addanimation (RA);    Ll.startanimation (AS); }}
View Code

The second type: XML file format:

1. Create the folder Anim under the Res path. To create an XML file in Anim

Such as:

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android"     >    <translate        android:duration= "        android:fromxdelta" = "0"         Android:fromydelta= "0"        android:toxdelta= "100%"        android:toydelta= "0" >    </translate>    <alpha        android:duration= "$"        Android:fromalpha = "0"        android:toalpha= "1" >    </alpha></set>
View Code

2. Write the following code where you want the animation:

Overridependingtransition (r.anim.next_in, R.anim.next_out)

Android (v) Animation 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.