The Animation in Android

Source: Internet
Author: User

The android provide the types of animation. Tween Animation is one,such as rotation,translation,scale,gradual change (gradient).


Main types:

Animation, Alphaanimation, Rotateanimation, Scaleanimation, Translateaniamtion, Animationset


1.AlphaAnimation

The first argument means the start transparency of animation,the second argument means the end transparency of the Animati On.


2.RotateAnimation

Arguments

Fromdegrees:start angle of the animation

Todegrees:end angle of the animation


3.ScaleAnimation

Arguments

Fromx:start scale in X cdoordination;

Tox:end scale in X coordination;

Fromy:start scale in Y coordination;

Toy:end scale in Y coordination;

On the other hand,you can set the scale Mode:pivotxtype/pivotytype,scale animation relative to X, y ' s start position:pivotx Value/pivotyvalue ect.


4.TranslateAnimation

Arguments

Fromxdelta:start X Coordination of animation

Toxdelta:end X Coordination of animation

Fromydelta:start Y Coordination of animation

Toydelta:end Y Coordination of animation


The layout file ' s code as bellow:

<?xml version= "1.0" encoding= "Utf-8"?> <absolutelayout android:layout_width= "Fill_parent" Android:layout_ height= "Fill_parent" xmlns:android= "http://schemas.android.com/apk/res/android" > <button android:id= "@+id/ Button_scale "android:layout_width=" wrap_content "android:layout_height=" wrap_content "android:text=" scale " android:layout_x= "5DP" android:layout_y= "383DP"/> <button android:id= "@+id/button_rotate" Android:layout_ Width= "Wrap_content" android:layout_height= "wrap_content" android:text= "rotate" android:layout_x= "158DP" Android: layout_y= "383DP"/> <button android:id= "@+id/button_alpha" android:layout_width= "Wrap_content" android:layout _height= "wrap_content" android:text= "Alpha" android:layout_x= "5DP" android:layout_y= "331DP"/> <button Android : id= "@+id/button_translate" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:text = "Translate" android:layout_x= "160DP" android:layout_y= "329DP"/> <button android:id= "@+id/Button_alpha_translate "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "android:text=" Alpha_translate "android:layout_x=" 84DP "android:layout_y=" 265DP "/> <imageview android:id=" @+id/imageview " Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_x= "105DP" Android:layout_  Y= "133DP" android:src= "@drawable/ic_launcher"/> </AbsoluteLayout>

The Class code:

 public class Animations_activity extends Activity {private button button1; private button button2; private button button 3; Private Button Button4; Private Button button5; Private ImageView ImageView; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.LAYOUT.ACTIVITY_ANIMATIONS_); button1= (Button) Findviewbyid (R.id.button_alpha); Button2= (Button) Findviewbyid (r.id.button_rotate); button3= (Button) Findviewbyid (R.id.button_scale); button4= (Button) Findviewbyid (r.id.button_translate); button5= (Button) Findviewbyid (r.id.button_alpha_translate); imageview= (ImageView) Findviewbyid (R.id.imageview); Button1.setonclicklistener (New MyButton ()); Button2.setonclicklistener (New MyButton ()); Button3.setonclicklistener (New MyButton ()); Button4.setonclicklistener (New MyButton ()); Button5.setonclicklistener (New MyButton ()); } class MyButton implements onclicklistener{@Override public void OnClick (View arg0) {//TODO auto-generated method Stub switch (Arg0.getid ()) {case R.id.button_alpha:alpha (), break, Case r.id.button_rotate:rotata (), break, Case R.id.butt On_scale:scale (); Break Case R.id.button_translate:translate (); Break Case R.id.button_alpha_translate:alpha_translate (); Break Default:break; }}//* 1. Create a Animationset object that stores a collection of animations * 2. Create the corresponding animation object as needed * 3. Set the corresponding data for the animation object (that is, the execution effect) according to the requirements of the animation * 4. Award Animati The on object is added to the Animationset Object * 5. Start execution with the control object Animationset */public void Alpha () {Animationset animationset=new animationset ( true); Alphaanimation alphaanimation=new alphaanimation (1, 0); Alphaanimation.setduration (2000); Animationset.addanimation (alphaanimation); Imageview.startanimation (Animationset); The public void Rotata () {Animationset animationset=new animationset (TRUE);//The four parameters that follow define the center position of the rotation rotateanimation Rotateanimation=new rotateanimation (0, Animation.relative_to_parent, 1f, animation.relative_to_parent, 0f); Rotateanimation.setduration (2000); Animationset.addanimation (rotateanimation); ImagEview.startanimation (Animationset); public void Scale () {Animationset animationset=new animationset (true); Scaleanimation scaleanimation=new scaleanimation (1, 0.1f, 1, 0.1f, animation.relative_to_self, 0.5f, Animation.relative_to_self, 0.5f); Scaleanimation.setduration (2000); Animationset.addanimation (scaleanimation); Imageview.startanimation (scaleanimation); } public void Translate () {Animationset animationset=new animationset (true); Translateanimation translateanimation=new translateanimation (animation.relative_to_self, 0f, start position of//x axis Animation.relative_to_self, 0.5f, end position of//x axis animation.relative_to_self, 0f, start position of//y axis animation.relative_to_self, 1.0f); The end position of the y-axis is translateanimation.setduration (2000); Animationset.addanimation (translateanimation); /* If the first line is set to true, the effect is fixed after execution after the animation is finished. * The second row is set to False if the effect is stopped after the animation has finished executing the state after execution * The third row sets a long value, which is the number of milliseconds after which the animation is deferred * Line four defines the animation to repeat several times */Animationset.setfillafter (TRUE); Animationset.setfillbefore (FALSE); Animationset.setstartoffset (2000); Animationset.setrepeatcount (3); Imageview.startanimation (Animationset); } public void Alpha_translate () {Animationset animationset=new animationset (true); Alphaanimation alphaanimation=new alphaanimation (1, 0); Alphaanimation.setduration (2000); Animationset.addanimation (alphaanimation); Translateanimation translateanimation=new translateanimation (animation.relative_to_self, 0f, start position of//x axis Animation.relative_to_self, 0.5f, end position of//x axis animation.relative_to_self, 0f, start position of//y axis animation.relative_to_self, 1.0f); The end position of the y-axis is translateanimation.setduration (2000); Animationset.addanimation (translateanimation); Imageview.startanimation (Animationset); } @Override Public boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu, this adds items to the action bar if it I s present. Getmenuinflater (). Inflate (R.menu.activity_animations_, menu); return true;  } }

If you also interest on Linux and Android embed system,please connection with us in QQ grounp:139761394


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.