Today I had a scenario, where I was performing following:
myViewGroup.setVisibility(View.GONE);
Right on the next frame I was performing an if
check somewhere else for visibility state of that view. Guess what? The following condition was passing:
if(myViewGroup.getVisibility() == View.VISIBLE) {
// this `if` was fulfilled magically
}
Placing breakpoints you can see, that visibility changes to GONE
, but right on the next frame it magically becomes VISIBLE
. I was trying to understand how the hell this could happen.
Turns out there was an animation applied to this view, which internally caused the view to change it's visibility to VISIBLE
until finishing the animation:
public void someFunction() {
...
TransitionManager.beginDelayedTransition(myViewGroup);
...
myViewGroup.setVisibility(View.GONE);
}
If you debug, you'll see that myViewGroup
indeed changes its visibility to GONE
, but right on the next frame it would again become visible in order to run the animation.
So, if you come across with such a situation, make sure you are not performing an if
check in amidst of animating the view.
You can remove all animations on the view via View.clearAnimation()
.