Frames-per-frame animation
/**
* 1. Add a single photo
* 2. Generate movie.xml entire picture
* 3. Use the image in the code Movie.xml
*/
iv= (ImageView) Findviewbyid (R.ID.IV);
Iv.setimageresource (R.drawable.movie);//load six photos for IV
Animationdrawable ad= (animationdrawable) iv.getdrawable ();//Get pictures to animated pictures
Ad.start ();
Displaymetrics dm = new Displaymetrics ();
GetWindow (). Getwindowmanager (). Getdefaultdisplay (). Getmetrics (DM);
int width = dm.widthpixels;//to get screen width
Motion Tweens, panning
1. Write directly through the code
Animation translate=new translateanimation (0, width, 0, 0);
Translate.setduration (2000);
Translate.setfillafter (TRUE);//After the animation is complete, stay in the position
Translate.setrepeatcount (2);//Repeat 2 times
Translate.setstartoffset (1000);//wait 1 seconds to move again
Iv.startanimation (translate);
2. Calling the XML file
Animation translate=animationutils.loadanimation (this, r.anim.push_to_right);
Iv.startanimation (translate);
Iv.setanimation (translate);
Animated Listener Events
Translate.setanimationlistener (New Animationlistener () {
@Override
public void Onanimationstart (Animation Animation) {
}
@Override
public void Onanimationrepeat (Animation Animation) {
}
@Override
public void Onanimationend (Animation Animation) {
Intent intent=new Intent (mainactivity.this,secondaty.class);
StartActivity (Intent);
Finish ();
}
});
}
Rotate animation
Angle from 0 to 360,pivotxtype who's X value (interface of? The picture itself) Pivotytype
Animation rotator = new Rotateanimation (0, 360,
Rotateanimation.relative_to_self, 0.5f,
Rotateanimation.relative_to_self, 0.5f);
Rotator.setduration (3000);
Rotator.setfillafter (TRUE);
Iv.startanimation (rotator);
Gradient
Animation alpha = new Alphaanimation (0, 0.9f);//from unseen to see 90%
Alpha.setduration (3000);
Alpha.setfillafter (TRUE);
Iv.startanimation (Alpha);
Stretch
FromX, ToX, FromY, toy translation Animation four parameters, x-axis telescopic size, y-axis telescopic size
Scaleanimation.relative_to_self, the 3f//x axis coordinates are 3 times times the width of your own picture.
Animation scale = new Scaleanimation (0, 0.3f, 0, 0.5f,
Scaleanimation.relative_to_self, 3f,
Scaleanimation.relative_to_self, 3f);
Scale.setduration (3000);
Scale.setfillafter (TRUE);
Iv.startanimation (scale);
Basics of Android Animation