Animating Specific Views

Animations must be applied and managed programmatically. Remember, costly operations, such as animations, should be stopped if the application is paused for some reason. The animation can resume when the application comes back into the foreground.

Let's start with a simplest case: applying the fade_in animation to your title TextView control, called TextViewTopTitle. All you need to do is retrieve an instance of your TextView control in the onCreate() method of the QuizSplashActivity class, load the animation resource into an Animation object, and call the startAnimation() method of the TextView control:

TextView logol = (TextView) findViewById(; Animation fadel = AnimationUtils.loadAnimation(this, R.anim.fade_in); logol.startAnimation(fadel);

When an animation must be stopped—for instance, in the onPause() method of the activity—you simply call the clearAnimation() method. For instance, the following onPause() method demonstrates this for the corner logos: ©Override protected void onPause() { super.onPause(); // Stop the animation

TextView logo1 = (TextView) findViewById(; logo1.clearAnimation();

TextView logo2 = (TextView) findViewById(; logo2.clearAnimation();

Was this article helpful?

0 0

Post a comment