I\'ve got the following LinearLayout...
Because you have to set the visibility to gone
if you want that the view takes no space.
Change invisible
by gone
that will do the trick.
public static final int View.INVISIBLE
This view is invisible, but it still takes up space for layout purposes. Use with setVisibility(int).
See View.GONE and View.INVISIBLE
invisible
will take up the same space as if it were visible
. Set the visibility to gone
if you want it to take up no space.
The documentation of Invisible says:
This view is invisible, but it still takes up space for layout purposes.
So setting the visibility of layout to invisible just hides the layout, but does not free the consumed space. If you want to do that you have to set the visibility to gone.
Gone does what you want:
This view is invisible, and it doesn't take any space for layout purposes.
See also: http://developer.android.com/reference/android/view/View.html#setVisibility(int)