Michel
Michel

Reputation: 23615

How to free up the space in the screen when a Linear Layout is hidden?

I want to show/hide a part of the window in my Android app.

I use this code for that:

LinearLayout l = (LinearLayout)findViewById(R.id.layoutToRemove);
        if (on) {
            l.setVisibility(View.INVISIBLE);
        } else {
            l.setVisibility(View.VISIBLE);
        }

Now what happens is that the LinearLayout is removed from the window, but the space it uses is not freed (so the rest of the UI is positioned at the original place)

Now what I want to accomplish is that the space is freed, and when the LinearLayout is made visible again, it takes it place again.

How should I do that?

Upvotes: 0

Views: 179

Answers (1)

WOUNDEDStevenJones
WOUNDEDStevenJones

Reputation: 5315

Use View.GONE instead of View.INVISIBLE

The documentation for GONE at http://developer.android.com/reference/android/view/View.html#GONE says

This view is invisible, and it doesn't take any space for layout purposes.

compared to INVISIBLE documentation at http://developer.android.com/reference/android/view/View.html#INVISIBLE which says

This view is invisible, but it still takes up space for layout purposes.

Upvotes: 3

Related Questions