This question arises from having to show/hide different views dynamicly. View's have 3 visibility settings - visible, invisible, and gone. If you have a parent view, for example a LinearLayout
, that has several child views (doesn't matter what they are) is setting the visibility of the parent the same as seting the visiblity on all the children independently? For example if I say
LinearLayout container = (LinearLayout) findViewById(R.id.layout_1);
container.setVisiblity(View.GONE);
Is that the same as finding each individual child view and setting all those visiblities to View.GONE
? What if the parent was not View.GONE
but View.INVISIBLE
? Are all the children still drawn but just not seen?
The effect is the same, but it does not actually set the visibility of all the children. It just won't draw them.
For instance:
Set child to GONE (parent is visible, child is gone)
Set parent to GONE (both gone)
Set parent to VISIBLE (parent visible, child still gone, since child was explicitly set before)
Set child to VISIBLE (both visible)
Any time a view is INVISIBLE, it won't draw it or its children. If it's GONE, it also won't reserve any layout space for them. If you check the child's getVisibility()
though, you'll see that it's still set to whatever it was before, even if it's not being drawn.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With