Effect of setting parent view visiblity on its children

14,927

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:

  1. Set child to GONE (parent is visible, child is gone)

  2. Set parent to GONE (both gone)

  3. Set parent to VISIBLE (parent visible, child still gone, since child was explicitly set before)

  4. 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.

Share:
14,927

Related videos on Youtube

Rarw
Author by

Rarw

I am lawyer, app developer and mobile privacy expert. I've developed apps for iOS, and am currently working on several android projects. In addition to developing apps I build programs using java/MySQL related to my work as a securities/commodities litigation associate at a New York law firm. This usually involves analyzing large quantities of market data and looking for patterns. Not always the most exciting job but it beats the hell out of reviewing documents all day. You can find me @echomeback or on Facebook and LinkedIn as myself. I am always interested in discussing programming problems, legal issues, or any combination of the two.

Updated on June 05, 2022

Comments

  • Rarw
    Rarw almost 2 years

    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?

  • Rarw
    Rarw over 10 years
    You have a link to anywhere in the docs it says that? I know when I set a parent layout to View.GONE it hides the children but does it "undraw" them or just make them invisible?
  • milosmns
    milosmns almost 8 years
    The behavior doesn't make sense to me, especially because it is different when working from XML inflation (i.e. visibility is propagated to children). Is there a workaround to make it consistent between XML and Java?