title: Android RelativeLayout, hiding views and pushing the views beneath up
body: <p>I have a <code>RelativeLayout</code> which includes a <code>Spinner</code> and some <code>RadioButton</code>s, based on the selection of these I have to hide some views and make others visible. The problem is if I make the views <code>GONE</code> by <code>view.setVisibility(View.GONE)</code> the layout gets messed up, the views overlap, if I use <code>view.Visibility(View.INVISIBLE)</code> everything is fine but the missing views create a void on the page. I want to push the views beneath up to properly augment the page. Below is a better explanation: </p>
  
  <p><img src="https://i.stack.imgur.com/uivZL.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/0lQIJ.png" alt="enter image description here"></p>
  
  <p>So far the code I have is: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:background="@drawable/bg_app" &gt;
  
      &lt;ScrollView
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:isScrollContainer="true"
          android:scrollbarAlwaysDrawVerticalTrack="true"
          android:scrollbarStyle="insideOverlay"
          android:scrollbars="vertical" &gt;
  
          &lt;RelativeLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_centerHorizontal="true" &gt;
  
              &lt;Spinner
                  android:id="@+id/spinner1"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_alignParentTop="true"
                  android:layout_centerHorizontal="true"
                  android:layout_marginLeft="20dp"
                  android:layout_marginRight="20dp"
                  android:layout_marginTop="60dp"
                  android:background="@drawable/drop_down" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView1"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_alignLeft="@+id/spinner1"
                  android:layout_below="@+id/textView5"
                  android:layout_marginTop="30dp"
                  android:text="xxx"
                  android:textColor="#002f44"
                  android:textSize="18sp" /&gt;
  
              &lt;Button
                  android:id="@+id/button2"
                  android:layout_width="170dp"
                  android:layout_height="30dp"
                  android:layout_alignBaseline="@+id/textView1"
                  android:layout_alignRight="@+id/spinner1"
                  android:background="@drawable/btn_calendar"
                  android:textColor="#FFBF00" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView3"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_alignParentLeft="true"
                  android:layout_alignParentTop="true"
                  android:visibility="invisible" /&gt;
  
              &lt;ImageView
                  android:id="@+id/imageView1"
                  android:layout_width="120dp"
                  android:layout_height="120dp"
                  android:layout_alignLeft="@+id/textView1"
                  android:layout_below="@+id/textView1"
                  android:layout_marginTop="20dp"
                  android:scaleType="centerCrop" /&gt;
  
              &lt;AutoCompleteTextView
                  android:id="@+id/editText1"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_alignRight="@+id/spinner1"
                  android:layout_alignTop="@+id/imageView1"
                  android:layout_marginLeft="10dp"
                  android:layout_marginTop="5dp"
                  android:layout_toRightOf="@+id/imageView1"
                  android:ems="6"
                  android:hint="xx xx"
                  android:inputType="textPersonName"
                  android:maxLength="25"
                  android:textColor="#002f44" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView2"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_alignLeft="@+id/editText1"
                  android:layout_below="@+id/editText1"
                  android:padding="03dp"
                  android:textColor="#610B0B" /&gt;
  
              &lt;Button
                  android:id="@+id/button1"
                  android:layout_width="120dp"
                  android:layout_height="50dp"
                  android:layout_alignLeft="@+id/textView2"
                  android:layout_below="@+id/textView2"
                  android:background="@drawable/btn_addreminder"
                  android:text="xxx"
                  android:textColor="#002f44"
                  android:textStyle="bold" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView4"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_alignLeft="@+id/spinner1"
                  android:layout_below="@+id/spinner1"
                  android:layout_marginTop="20dp"
                  android:text="xxx "
                  android:textColor="#002f44"
                  android:textSize="18sp" /&gt;
  
              &lt;RadioGroup
                  android:id="@+id/radioGroup1"
                  android:layout_width="180dp"
                  android:layout_height="wrap_content"
                  android:layout_alignRight="@+id/spinner1"
                  android:layout_alignTop="@+id/textView4"
                  android:layout_marginTop="-5dp"
                  android:background="@drawable/widget_style"
                  android:orientation="horizontal" &gt;
  
                  &lt;RadioButton
                      android:id="@+id/radio0"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:checked="true"
                      android:text="xxx"
                      android:textColor="#002f44" /&gt;
  
                  &lt;RadioButton
                      android:id="@+id/radio1"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_marginLeft="25dp"
                      android:text="xxx"
                      android:textColor="#002f44" /&gt;
              &lt;/RadioGroup&gt;
  
              &lt;TextView
                  android:id="@+id/textView5"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_alignLeft="@+id/spinner1"
                  android:layout_below="@+id/radioGroup1"
                  android:layout_marginTop="25dp"
                  android:text="xxx"
                  android:textColor="#002f44"
                  android:textSize="18sp" /&gt;
  
              &lt;AutoCompleteTextView
                  android:id="@+id/autoname"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_alignBaseline="@+id/textView5"
                  android:layout_alignRight="@+id/spinner1"
                  android:ellipsize="end"
                  android:ems="8"
                  android:hint="xx xx"
                  android:maxLines="1"
                  android:scrollHorizontally="true"
                  android:singleLine="true"
                  android:textAppearance="?android:attr/textAppearanceMedium"
                  android:textColor="#002f44" &gt;
              &lt;/AutoCompleteTextView&gt;
  
              &lt;Button
                  android:id="@+id/button4"
                  android:layout_width="100dp"
                  android:layout_height="40dp"
                  android:layout_alignLeft="@+id/imageView1"
                  android:layout_below="@+id/button1"
                  android:layout_marginLeft="05dp"
                  android:layout_marginTop="66dp"
                  android:background="@drawable/btn_addreminder"
                  android:text="xxx"
                  android:textColor="#002f44"
                  android:textStyle="bold" /&gt;
  
              &lt;Button
                  android:id="@+id/Button01"
                  android:layout_width="100dp"
                  android:layout_height="40dp"
                  android:layout_alignParentBottom="true"
                  android:layout_centerHorizontal="true"
                  android:background="@drawable/btn_addreminder"
                  android:text="xxx"
                  android:textColor="#002f44"
                  android:textStyle="bold" /&gt;
  
              &lt;Button
                  android:id="@+id/Button02"
                  android:layout_width="100dp"
                  android:layout_height="40dp"
                  android:layout_alignBaseline="@+id/button4"
                  android:layout_alignBottom="@+id/button4"
                  android:layout_alignRight="@+id/editText1"
                  android:background="@drawable/btn_addreminder"
                  android:text="xxx"
                  android:textColor="#002f44"
                  android:textStyle="bold" /&gt;
          &lt;/RelativeLayout&gt;
      &lt;/ScrollView&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>