minipif minipif - 1 year ago 127
Android Question

Is INVISIBLE more efficient than GONE?

For a

that is sometimes visible and sometimes not, depending on the user's actions, (staying in the same activity) what is more efficient to hide the view?

myView.setVisibility(View.INVISIBLE); // or

No other element depends on
's size or dimensions, so the graphical result is the same.

As INVISIBLE doesn't change the view's dimensions, I guess it's more efficient than GONE because with GONE we possibly have to mesure and redraw other views unnecessarily. And then re-mesure and re-draw them when
is made VISIBLE again.

Answer Source

You're on the right track thinking about the impact on measuring. Which one is more efficient all depends on how frequently you are changing the view's visibility.

For example, if the view is not visible for a majority of the time, making it GONE would probably be more efficient, because the system would not be needlessly measuring and laying out your invisible view whenever it needs to adjust other views on the screen.

On the other hand, if the view changes between visible and invisible frequently, you might get better performance from INVISIBLE as you would potentially avoid an extra measure/layout on each transition.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download