Android Animation Listener Events

Source: Internet
Author: User

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

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.