Exploring the Animation Listener Class

Android uses a listener interface called AnimationListener to monitor animation events (see Listing 6-18). You can listen to these animation events by implementing the AnimationListener interface and setting that implementation against the Animation class implementation.

Listing 6-18. An Implementation of the AnimationListener Interface public class ViewAnimationListener implements Animation.AnimationListener {

private ViewAnimationListener(){}

public void onAnimationStart(Animation animation)

Log.d("Animation Example", "onAnimationStart");

public void onAnimationEnd(Animation animation)

Log.d("Animation Example", "onAnimationEnd");

public void onAnimationRepeat(Animation animation)

Log.d("Animation Example", "onAnimationRepeat");

The ViewAnimationListener class just logs messages. You can update the animateListView method in the view-animation example (see Listing 6-17) to take the animation listener into account:

private void animateListView() {

ListView lv = (ListView)this.findViewById(R.id.list_view_id); ViewAnimation animation = new ViewAnimation(); animation.setAnimationListener(new ViewAnimationListener()):


0 0

Post a comment