How to hide linearlayout from java code?

I want to hide the linear layout, so I used

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

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

+42
android
Nov 19 '10 at 15:44
source share
5 answers

Using:

 mainLayout.setVisibility(LinearLayout.GONE); 
+119
Nov 19 '10 at 15:47
source share

You can also set the visibility in your .xml layout if you want it to be hidden when your application first starts. android:visibility="gone" should do the trick. Thus, it is hidden from the very beginning when the layout is initialized by your application.

+18
Nov 19 '10 at 16:34
source share

The constant value used is incorrect. This should be 8 for GONE. 4 for INVIVIBLE and 0 for VISIBLE.

Check View description from developer site.

And this link .

+10
Oct. 18 '12 at 10:50
source share

You can also use LinearLayout. INVISIBLE

The difference is ( Documentation for Android ):

View.GONE - This view is invisible, and does not occupy a space for the layout.

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

You can choose any based on your design.

+9
Oct 17 '12 at 11:40
source share

Using:

 mainLayout.setVisibility(LinearLayout.INVISIBLE); 
0
Feb 05 '13 at 8:51
source share



All Articles