Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Alpha Animation: Alpha value jumps back to old value after Animation ended

I have a ImageButton View on a Layout. If the users clicks the ImageButton the button should fade out.

The buttons fadeout animation will be started like this:

public void buttonClicked(View aButton){

    final Animation aAnim = new AlphaAnimation(1.0f, 0.0f);
    aAnim.setDuration(500);

    aButton.startAnimation(aAnim);

}

This works, but as soon as the ImageButton is faded out, its Alpha Value jumps right back to 1.0 and the button is visible again.

I solved it temporarily with a Animation Listener that sets the ButtonImage to invisible at the end of the Animation but that seems to be a odd solution to me.

What do I have to do to keep the buttons Alpha Value at its last value of the Animation?

Thank You.

like image 946
Tom Avatar asked May 25 '12 14:05

Tom


2 Answers

If you want to set new value when animation finished, you must set the 'setFillAfter' to true.

public void buttonClicked(View aButton){    
    final Animation aAnim = new AlphaAnimation(1.0f, 0.0f);
    aAnim.setDuration(500);

    aAnim.setFillAfter(true);
    aButton.startAnimation(aAnim);
}
like image 69
Salman Amintabar Avatar answered Nov 09 '22 21:11

Salman Amintabar


try using aAnim.setFillAfter(true);

like image 29
MikeT Avatar answered Nov 09 '22 20:11

MikeT