I have items in my View which are displayd on click and does not show up on that start of the activity. Now everything works fine but when i use the graphical layout tool i see those items and it makes working with it harder.
Meaning, i have a ListView with items, i see those items on top of everything.
How can i hide those elements? setting the visibility programaticlly dosen't help. Should i do something like setting alpha to 0 and then add it instead of making items invisible? Seems like a dumb idea, there must be some option i'm missing.
Help anyone?
Thanks, Eric
Why not set the visibility to 'gone': android:visibility="gone"
? That will prevent layout items from showing up and taking up space in the layout.
Alternatively, if some elements in your view hierarchy may never be shown to the user at all, you could use ViewStub
s to 'lazily' load them at runtime. A ViewStub
is simply a placeholder for some other view (hierarchy) and is empty and zero-sized by itself. It's a good way of separating your view hierarchy into default and optional elements, and can potentialy reduce the complexity of the view hierarchy at runtime significantly.
If you want to hide the element programmatically / conditionally instead of in the layout XML as suggested above and setting the visibility wasn't working, perhaps your syntax was wrong? This is how you programmatically hide an element:
element.setVisibility(View.GONE);
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