[Android] Showing and Hiding the views

Public on April 30, 2014

Android Showing and Hiding the views

You can show and hide android views (layout, button, textview etc.,) at any time. You can also use animations like fadeOut or fadeIn to make it more beautiful while hiding and showing the views.
Please refer Android Working with XML Animations if you want to add animations to view while hiding/showing.
Using view.setVisibility(int) function you can show and hide the view by appropriate value.
Method 1

Hide the view using View.GONE

If you use View.GONE value, the element will be removed from the layout hence it won’t occupy any space in the layout.
Button btnSend = findViewById(R.id.btnSend);
// hiding the button
Method 2

Hide the view using View.INVISIBLE

If you use View.INVISIBLE value, the element won’t display but it take it’s space in the layout as the element still be added to the layout.
// hiding the button

Showing the view

And showing can be done using View.VISIBLE value
// showing the button

[Advertising]Faster Thinking - Speed up your brain

Faster Thinking Game

sentiment_satisfied Emoticon