Package Com.example.coco_demo02;import Android.app.activity;import Android.os.bundle;import Android.view.animation.animation;import Android.view.animation.translateanimation;import Android.widget.imageview;import android.widget.linearlayout;/* * This method is suitable for these four basic animations: *alphaanimation Transparency Change * Rotateanimation screen rotation *scaleanimation size zoom *translateanimation position Move */public class Mainactivity extends Activity {@ overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);//Instantiate Layout LinearLayout Llayout = new LinearLayout (this);//Added to this activity This.setcontentview (llayout);//Instantiate picture, set high width, and add to layout imageview image = New ImageView (this); Image.setmaxheight (image.setmaxwidth); image.setpadding (10, 0, 0, 0); Image.setimageresource (R.drawable.ic_launcher); Llayout.addview (image);//Set position, Parameter: Start x, start Y, end X, End Ytranslateanimation animation = new Translateanimation (0, 0, 0, 50);//Run Time animation.setduration (3000);//Repeat number, Do not write only once Animation.setrepeatcount (animation.infinite);//repeating mode, reversE is the beginning to the end, and then the animation reverts to the beginning Animation.setrepeatmode (animation.reverse);//The position after the animation//Animation.setfillafter (TRUE);// Animate the picture image.setanimation (animation);//animation starts Animation.start ();}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
15th chapter, Cycle Animation (Android)