Android : difference between invisible and gone?

AndroidAndroid XmlXml Attribute

Android Problem Overview


What is the difference between invisible and gone for the View visibility status?

Android Solutions


Solution 1 - Android

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.

Solution 2 - Android

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

enter image description here

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

enter image description here

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

enter image description here

Hope this will clear your doubts.

Solution 3 - Android

For ListView or GridView there is an another difference, when visibility initially set to

INVISIBLE:

> Adapter's getView() function called

GONE:

> Adapter's getView() function didn't call, thus preventing views to load, when it is unnecessary

Solution 4 - Android

INVISIBLE:
The view has to be drawn and it takes time.

GONE:
The view doesn't have to be drawn.

Solution 5 - Android

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.

Solution 6 - Android

when you make it Gone every time of compilation of program the component gets initialized that means you are removing the component from layout and when you make it invisible the component it will take the same space in the layout but every time you dont 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.

Solution 7 - Android

  • View.INVISIBLE->The View is invisible but it will occupy some space in layout

  • View.GONE->The View is not visible and it will not occupy any space in layout

Solution 8 - Android

View.GONE = The view will not show and the rest of the views will not take its existence into consideration

View.INVISIBLE = The view will not show, but it will take its assigned space in the layout

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRobView Question on Stackoverflow
Solution 1 - AndroidIñigoView Answer on Stackoverflow
Solution 2 - AndroidPankaj KumarView Answer on Stackoverflow
Solution 3 - AndroidmesView Answer on Stackoverflow
Solution 4 - AndroidtwlkyaoView Answer on Stackoverflow
Solution 5 - AndroidRafael Ruiz MuñozView Answer on Stackoverflow
Solution 6 - Androidkuldeep zalaView Answer on Stackoverflow
Solution 7 - AndroidYugandhar VadlamudiView Answer on Stackoverflow
Solution 8 - AndroidMKHView Answer on Stackoverflow