How do you hide multiple views at once?

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); } 
+6
source share
4 answers

solved. Then uninstalling and then installing the application on my Android device did the trick. I will beware of this in the future.

0
source

You must set View.GONE .

+2
source

Try setting all three views to View.INVISIBLE or View.GONE .

OR

You may try

 public void onClick(View v) { //Toggle viewing of options, using "if" in case it is set to View.GONE RelativeLayout view = (RelativeLayout) findViewById(R.id.optionsform); if (view.getVisibility() == View.VISIBLE) view.setVisibility(View.INVISIBLE); else view.setVisibility(View.VISIBLE); } 
+2
source
  <TextView android:id="@+id/tvdictionary" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" **android:layout_below="@+id/tvoptions"** // *should be 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"** // *should be android:layout_alignTop="@id/tvdictionary* android:layout_alignParentRight="true" android:layout_marginTop="-10dp" android:layout_marginLeft="6dp" android:layout_toRightOf="@+id/tvdictionary"// *should be android:layout_toRightOf="@id/tvdictionary* /> 

@id is used when referring to the layout identifier

@ + id is used when creating a new layout identifier

+1
source

Source: https://habr.com/ru/post/901823/