Reputation: 3061
What is the android equivalent of the CSS style attribute display:none?
In web pages the display:none stylesheet causes the web page element to which it is applied to be hidden and not occupy any space. When the element's attribute is changed dynamically using Javascript to visible, the browser shows the element moving any other elements surrounding it.
Upvotes: 26
Views: 20633
Reputation: 4245
you can use setVisibility
on a view.
There are 3 options available
VISIBLE - seen by the user
INVISIBLE - not seen by the user. But the view still takes some space.
GONE - not seen by the user, and the view doesn't take up any space.
Adding examples
4 Text views in a LinearLayout
oriented vertically, all visible
4 Text views in a LinearLayout
oriented vertically, 2 set to invisible
4 Text views in a LinearLayout
oriented vertically, 2 set to gone
Upvotes: 45
Reputation: 3123
android:visibility="gone"
or in code: [element].setVisibility(View.GONE);
This is the equivalent of display:none in CSS.
There's also android:visibility="invisible"
or .setVisibility(View.INVISIBLE)
which is the equivalent of visibility:hidden in CSS - i.e. the element is hidden but still takes up space in the layout.
setVisibility Android docs
android:visibility docs
Upvotes: 11
Reputation: 13182
You can use:
button.setVisibility(view.GONE);
Also
button.setVisibility(view.INVISIBLE);
button.setVisibility(view.VISIBLE);
Upvotes: 3