Header Ads

[Android] Showing and Hiding the views

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
btnSend.setVisibility(View.GONE);
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
btnSend.setVisibility(View.INVISIBLE);

Showing the view

And showing can be done using View.VISIBLE value
// showing the button
btnSend.setVisibility(View.VISIBLE);

No comments:

Powered by Blogger.