I have a RelativeLayout view, and 3 children’s views too. I’m trying to hide them all in code by setting the relative layout to INVISIBLE using setVisibility. The funny thing is that when I use setVisibility(View.INIVISIBLE) only the first child is hidden, not the other two. So I’m a bit confused – if I set a parent view to invisible shouldn’t it change the visibility of all the children or leave them all alone?
Feel free to point me to a reference page that explains it – I can’t find anything.
Update: I’ve tried setting it to View.GONE, but the same thing happens, except the two children who remain visible move up a bit.
Here’s 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’s the relevant code I’m using:
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);
}
Solved. An uninstall then install of the app on my android device did the trick. I’ll beware of that in future