53

I want to hide the linear layout so i used

LinearLayout mainLayout=(LinearLayout)this.findViewById(R.id.mainLayout);
mainLayout.setVisibility(2);

but why is doesn't hide ??!!!

Adham
  • 63,550
  • 98
  • 229
  • 344

5 Answers5

137

Use:

mainLayout.setVisibility(LinearLayout.GONE);
james
  • 26,141
  • 19
  • 95
  • 113
21

You can also set the visibility in your layout.xml if you want it hidden when your application first starts. android:visibility="gone" should do the trick. This way it is hidden from the very start when the layout is initialized by your app.

Marc Bernstein
  • 11,423
  • 5
  • 34
  • 32
13

Also you can use LinearLayout.INVISIBLE.

The difference is (Android Documentation):

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

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

You can choose anyone based upon your design.

Shahul3D
  • 2,129
  • 1
  • 15
  • 16
9

The constant value used is wrong. It should be 8 for GONE. 4 for INVISIBLE and 0 for VISIBLE.

Check this View description from the developer's site.

And this link.

Community
  • 1
  • 1
Joseph
  • 261
  • 2
  • 7
1

Use:

mainLayout.setVisibility(LinearLayout.INVISIBLE);
i18n
  • 130
  • 5