I have a relative layout view and 3 children views. I am trying to hide them all in code by setting the relative INVISIBLE layout using setVisibility. The funny thing is that when I use setVisibility (View.INIVISIBLE), only the first child is hidden, and not the other two. Therefore, I am a little confused - if I set the parental view to invisible, should I not change the visibility of all the children or leave them alone?
Feel free to point me to the link page that explains this - I cannot find anything.
Update: I tried installing it in View.GONE, but the same thing happens, except for two children who remain visible, going up a little.
Here is the relevant XML:
<RelativeLayout android:id="@+id/optionsform" android:layout_width="fill_parent" android:padding="8dp" android:layout_height="wrap_content" > <TextView android:id="@+id/tvoptions" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:text="@string/tvoptions" android:textColor="#f000" android:textAppearance="?android:attr/textAppearanceMedium" android:textStyle="bold"/> <TextView android:id="@+id/tvdictionary" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/tvoptions" android:layout_marginLeft="30dp" android:layout_marginTop="16dp" android:text="@string/dictionary" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#f000" /> <Spinner android:id="@+id/dictionary" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/tvdictionary" android:layout_alignParentRight="true" android:layout_marginTop="-10dp" android:layout_marginLeft="6dp" android:layout_toRightOf="@+id/tvdictionary" /> </RelativeLayout>
And here is the corresponding code that I use:
public void onClick(View v) { //Toggle viewing of options, using "if" in case it is set to View.GONE View view = findViewById(R.id.optionsform); if (view.getVisibility() == View.VISIBLE) view.setVisibility(View.INVISIBLE); else view.setVisibility(View.VISIBLE); }
source share