What is the difference between View.INVISIBLE and View.GONE for the View visibility status?
-
35When a View is gone, it means it doesn't take any space in the layout. When it is invisible, it will take the necessary room in a layout but you just don't see it.DroidBender– DroidBender2012-07-19 08:16:02 +00:00Commented Jul 19, 2012 at 8:16
8 Answers
INVISIBLE:
This view is invisible, but it still takes up space for layout purposes.
GONE:
This view is invisible, and it doesn't take any space for layout purposes.
7 Comments
display:none & visibility:hidden in HTML/CSS :-)From Documentation you can say that
View.GONE This view is invisible, and it doesn't take any space for layout purposes.
View.INVISIBLE This view is invisible, but it still takes up space for layout purposes.
Lets clear the idea with some pictures.
Assume that you have three buttons, like below

Now if you set visibility of Button Two as invisible (View.INVISIBLE), then the output will be

And when you set visibility of Button Two as gone (View.GONE) then the output will be

Hope this will clear your doubts.
1 Comment
I'd like to add to the right and successful answers, that if you initialize a view with visibility as View.GONE, the view could have been not initialized and you will get some random errors.
For example if you initialize a layout as View.GONE and then you try to start an animation, from my experience I've got my animation working randomly times. Sometimes yes, sometimes no.
So before handling (resizing, move, whatever) a view, you have to init it as View.VISIBLE or View.INVISIBLE to render it (draw it) in the screen, and then handle it.
1 Comment
GONEwhen you make it Gone every time of compilation of the program the component gets initialized which means you are removing the component from the layout and when you make it invisible the component it will take the same space in the layout but every time you don't need to initialize it.
if you set Visibility=Gone then you have to initialize the component..like
eg
Button _mButton = new Button(this);
_mButton = (Button)findViewByid(R.id.mButton);
so it will take more time as compared to Visibility = invisible.