setVisibility(View.GONE) doesn't disappear a view

android

Solution

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);
}

Problem

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.

Original source