3

In my activity, I have a start button, and when that's clicked it should fade out and finally disappear by setVisibility(View.GONE)

The problem is setting visibility to GONE doesn't disappear the view, it's still visible. I've purposefully made the view animation fade out to 0.1 (instead of 0) and I can see it in the background even after I've called setVisibility(View.GONE) on it.

The fadeout animation anim_fade_out.xml is:

<?xml version="1.0" encoding="utf-8"?>
<set
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"
    android:fillAfter="true" android:fillEnabled="true">

        <alpha
            android:fromAlpha="1.0"
            android:toAlpha="0.1"
            android:duration="200" />
</set>

The method is showTimer():

private void showTimer() {
    final LinearLayout startButtonArea = (LinearLayout)findViewById(R.id.startButtonArea);      

    Animation animFadeOut = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.anim_fade_out);

    startButtonArea.startAnimation(animFadeOut);

    animFadeOut.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationEnd(Animation animation) {
            startButtonArea.setVisibility(View.GONE);
            Log.d("Animation ended","startButtonArea SHOULD BE GONE BUT IT ISN'T");
        }
        @Override
        public void onAnimationRepeat(Animation animation) {}
        @Override
        public void onAnimationStart(Animation animation) {}    
    });

}

To reiterate, I know that the end alpha of the animation is 0.1 (it would be 0 usually) but I want to confirm that the view is really GONE and it isn't.

1
  • Try using INVISIBLE instead of gone Commented Jan 11, 2014 at 12:36

1 Answer 1

7

Because your fillAfter is true, the animation sets the properties after your onAnimationEnd is called. You can either change fillAfter to false, or do it like this:

@Override
public void onAnimationEnd(Animation animation) {
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            startButtonArea.setVisibility(View.GONE);
            Log.d("Animation ended","startButtonArea SHOULD BE GONE BUT IT ISN'T");
        }
    }, 0);
}
Sign up to request clarification or add additional context in comments.

2 Comments

Yeah, that's it. Serves me right for just copying the animation XML without understanding every bit of it.
Nah, we are developers. Thats what we do :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.