Reputation: 65
What is the difference between removing a view from it's parent and setting it's visibility as GONE?
Upvotes: 4
Views: 1776
Reputation: 180
If you set a View's visibility GONE, it will look like it doesn't exist anymore, but it actually exists inside its parent, it is there, you can still manipulate it at your will, however, if you remove that view from its parent it will be actually out of it with all the consequences. For instance: If you remove a view from a LinearLayout, it won't be inside of that linearLayout, and therefore it won't be affected by its parent gravity, but if you just set your view visibility GONE, it'll be still affected by its parent gravity, even if you can't see it because your view is invisible.
I'm sorry if it sounds a little bit unclear, but it is kind of hard to explain for me.
Upvotes: 0
Reputation: 93708
If you remove a view from the parent, its no longer in its list of children. You can then add it to any other ViewGroup. If you loop through the old paren't children it won't come up, and it won't be called when the ViewGroup does things like resize itself.
If you make it GONE, its still a child of the ViewGroup. It can't be added to another, because it can have only 1 parent. It will still be called for things like resizing of the view group.
Upvotes: 6