public class Guideactivity extends Activity {
Display the ImageView component of a picture
Private ImageView guidepicture;
A set of picture resources to show
Private drawable[] pictures;
A set of animation effects to be performed for each display image
Private animation[] animations;
How many pictures are currently being executed (resource index)
private int currentitem = 0;
@Override
protected void OnCreate (Bundle savedinstancestate) {
TODO auto-generated Method Stub
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_guide);
Initview ();
InitData ();
}
private void Initview () {
Instantiate a ImageView boot image
Guidepicture = (ImageView) Findviewbyid (r.id.guide_picture);
Instantiate an array of boot images
Pictures = new drawable[] {
Getresources (). Getdrawable (R.drawable.guide_pic1),
Getresources (). Getdrawable (R.drawable.guide_pic2),
Getresources (). Getdrawable (R.DRAWABLE.GUIDE_PIC3)};
Instantiate an array of animation effects
animations = new animation[] {
Animationutils.loadanimation (this, r.anim.guide_fade_in),
Animationutils.loadanimation (this, R.anim.guide_fade_in_scale),
Animationutils.loadanimation (this, r.anim.guide_fade_out)};
}
private void InitData () {
Set the playback time for each animation effect
Animations[0].setduration (1500);
Animations[1].setduration (3000);
Animations[2].setduration (1500);
Set listener events for each animation effect
Animations[0].setanimationlistener (New Guideanimationlistener (0));
Animations[1].setanimationlistener (New Guideanimationlistener (1));
Animations[2].setanimationlistener (New Guideanimationlistener (2));
Set Picture animation Initialization default value is 0
Guidepicture.setimagedrawable (Pictures[currentitem]);
Guidepicture.startanimation (Animations[0]);
}
Class Guideanimationlistener implements Animationlistener {
private int index;
public guideanimationlistener (int index) {
TODO auto-generated Constructor stub
This.index = index;
}
@Override
public void Onanimationstart (Animation Animation) {
TODO auto-generated Method Stub
}
Rewrite the listener event at the end of the animation to achieve the effect of animation loop playback
@Override
public void Onanimationend (Animation Animation) {
TODO auto-generated Method Stub
if (Index < (animations.length-1)) {
guidepicture.startanimation (Animations[index + 1]);
} else {
currentitem++;
if (CurrentItem > (pictures.length-1)) {
CurrentItem = 0;
}
Guidepicture.setimagedrawable (Pictures[currentitem]);
Guidepicture.startanimation (Animations[0]);
}
}
@Override
public void Onanimationrepeat (Animation Animation) {
TODO auto-generated Method Stub
}
}
}
Marked in red, when each startanimation, Guideanimationlistener objects are not the same, so the value of index once is 0, 1, 2
Android Animation Listener Events