Reputation: 1435
So I have a textview
at the top of my screen and eight buttons in the middle. What I would like to happen is for the textview
to slide in from the right (animation) and then whenever the user clicks a button it makes the textview
fade out, changes the text, and then fade back in with the new text. The fading back in and changing the text works fine, but instead of fading out the textview
just disappears. The textview
also has a problem with the slide in from the left animation in onCreate
so i figured it may be something I am missing to do with the textview
. Here is my code, someone please help mehh!!
private void AnimationMethodForButtons(TextView TitleArea, int explanation){
ObjectAnimator fadeOut = ObjectAnimator.ofFloat(TitleArea, "alpha", 1.0f, 0.0f);
fadeOut.setDuration(3000);
fadeOut.start();
ObjectAnimator fadeIn = ObjectAnimator.ofFloat(TitleArea, "alpha", 0.0f, 1.0f);
fadeIn.setDuration(3000);
TitleArea.setText(explanation);
fadeIn.start();
}
Upvotes: 0
Views: 1015
Reputation: 20211
The start()
call is asynchronous. You should be using an AnimatorListener
if you want to do something at the end of an animation.
private void AnimationMethodForButtons(final TextView title, final int explaination){
ObjectAnimator fadeOut = ObjectAnimator.ofFloat(title, "alpha", 1.0f, 0.0f);
fadeOut.setDuration(3000);
final ObjectAnimator fadeIn = ObjectAnimator.ofFloat(title, "alpha", 0.0f, 1.0f);
fadeIn.setDuration(3000);
fadeOut.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
title.setText(explaination);
fadeIn.start();
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
fadeOut.start();
}
Upvotes: 1