There is the way to change visibility of View, but how can I change programmatically visibility of layout defined in XML? How to get layout object?
<LinearLayout
android:id="@+id/contacts_type"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone">
</LinearLayout>
You can change layout visibility just in the same way as for regular view. Use setVisibility(View.GONE) etc. All layouts are just Views, they have View as their parent.
Have a look at
View.setVisibility(View.GONE / View.VISIBLE / View.INVISIBLE)
.From the API docs:
Note that
LinearLayout
is aViewGroup
which in turn is aView
. That is, you may very well call, for instance,myLinearLayout.setVisibility(View.VISIBLE)
.This makes sense. If you have any experience with AWT/Swing, you'll recognize it from the relation between
Container
andComponent
. (AContainer
is aComponent
.)programaticaaly use this :
Use this Layout in your xml file
Define your layout in .class file
Now if you want to shoe this layout just write
and if you want to hide layout just write