stefple
stefple

Reputation: 558

Android: Hide a LinearLayout onKeyDown

I have a LinearLayout which holds a couple of buttons. To give the user more (drawing)space on the screen i want to hide this LinearLayout on Menu press:

if (keyCode == KeyEvent.KEYCODE_MENU) {

                if (showButtons) {
                    showButtons = false;
                    LinearLayout lay = (LinearLayout) this.findViewById(R.id.buttonLayout);
                    laySize = lay.getHeight();

                    go2trimsecond();
                } else {
                    showButtons = true;
                    go2trimsecond();
                }

I thought i just save the height in if(showButtons), change the maxHeight of the layout to 0 and change it back on if(!showButtons), but unfortunatly i was thinking wrong, since there is no setMaxHeight. Any idea how i should do this ?

Upvotes: 2

Views: 402

Answers (2)

Suresh
Suresh

Reputation: 8363

Hi stefple, It would be a good help if you elaborate your need. But what i understood from your recent post i wanna suggest one solution.

As you have instance of your layout as lay.

just do lay.setVisiblity(View.GONE) or lay.setVisiblity(View.INVISIBLE); and in case you wanna show it again just do

lay.setVisibility(View.VISIBLE);

Remember one thing View.GONE will free the space occupied by your linear layout whereas View.INVISIBLE will keep the space occupied but just hide the layout.

Upvotes: 2

Timuçin
Timuçin

Reputation: 4673

No need to change layout height. Since LinearLayout is also a View, you can call setVisibility(int) method on your layout.

Upvotes: 1

Related Questions