views:

64

answers:

2

There is the way to change visibility of View, but how can I change programaticly 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>
+6  A: 

Have a look at View.setVisibility(View.GONE / View.VISIBLE / View.INVISIBLE)?

From the API docs:

public void setVisibility(int visibility)

    Since: API Level 1

    Set the enabled state of this view.
    Related XML Attributes: android:visibility

Parameters:
visibility     One of VISIBLE, INVISIBLE, or GONE.

Note that LinearLayout is a ViewGroup which in turn is a View. 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 and Component. (A Container is a Component.)

aioobe
I'm asking about LAYOUT not VIEW.
darbat
LinearLayout inherits from a View so this should work http://developer.android.com/reference/android/widget/LinearLayout.html
ccheneson
Clarified my answer. Thanks for the down-votes ;)
aioobe
A: 

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.

Konstantin Burov