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 ?? !!!
Using:
mainLayout.setVisibility(LinearLayout.GONE);
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.
android:visibility="gone"
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 .
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.
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.
mainLayout.setVisibility(LinearLayout.INVISIBLE);