Search this blog

How to animate Specific Views in android

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 theforeground.
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 logo1 = (TextView) findViewById(R.id.TextViewTopTitle);
Animation fade1 = AnimationUtils.loadAnimation(this, R.anim.fade_in);
logo1.startAnimation(fade1);

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(R.id.TextViewTopTitle);
logo1.clearAnimation();
TextView logo2 = (TextView) findViewById(R.id.TextViewBottomTitle);
logo2.clearAnimation();
// ... stop other animations
}

0 comments:

Post a Comment