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(;

// 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

Ravi is hardcore Android programmer and Android programming has been his passion since he compiled his first hello-world program. Solving real problems of Android developers through tutorials has always been interesting part for him.

  • Arul

    It’s really so nice of all posts.,thank you…..!

  • Nischay Nahata

    Hi Ravi, first of all thanks for writing one of the best series of android tutorials. Do you have a tutorial on animations where the layouts switch on pressing a button (without changing the activity) and it reverts back on pressing the back button

  • Uche Philip


  • jounes

    Hello Mr Ravi Tamada …can i ask you for hellp!!…

    I have a problem with my android interface, when i created user forms ..i need to display different Spinner …where the seconds spinner it’s depend from the first

    exempl:1- i have the first spinner called “categories”,

    “categories” =item 1
    item 2
    item 3

    2-the second spinner called “type”

    What i need its :when i click in the “item 1” from the first spinner,i don’t need to show the second spinner…and when i click in the “item 2” the second spinner are shown in the interface

    can you sir to give me a idea to program that .


  • savari sagaya devan s

    Thanks for this

  • Raza Jamakhan

    how to display linearlayout from adapter click listener in android studio

    • Can you elaborate your question?

      • Raza Jamakhan

        thank you for your response bro,
        I am displaying a recycler grid view in my fragment and i placed checkbox in gridview items
        if i click on the checkbox from grid item it should display a linear layout on the bottom side which had a options to delete or share that gridview item

  • pradeepkumar reddy

    after i set the visibility as GONE, can i make the visibility as VISIBLE again in code ?

  • gunjan Yadav

    how can i hide the empty list in listview……..when no one data is set in list

  • Natesh

    Hi this is Natesh. I need to Hide and Show the button automatically. Very first time button is visible then I need to decrement the seconds from 10 to 1, the button is GONE, then wait for 2 secs and then increment from 0 to 10 secs then the hidden button should be visible.