Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide elements in graphical layout?

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

like image 952
eric.itzhak Avatar asked May 01 '12 19:05

eric.itzhak


2 Answers

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

like image 190
MH. Avatar answered Oct 31 '22 22:10

MH.


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);
like image 25
ashack Avatar answered Oct 31 '22 22:10

ashack