title: Android ScrollView scrolls to top after calling setVisibility(View.VISIBLE) on child view
body: <p>I have a <code>ScrollView</code> with a <code>RelativeLayout</code> inside it. This <code>RelativeLayout</code> then has several <code>View</code>s inside it. One of these several <code>View</code>s is a <code>CheckBox</code>. When the <code>CheckBox</code> is checked/unchecked, some of the other <code>View</code>s should appear/disappear accordingly.The appearing and disappear is working fine, but every time the target <code>View</code>s appear or disappear, the <code>ScrollView</code> scrolls all the way to the top and I'm forced to scroll down to see what happened.</p>
  
  <p>The code I use to control visibility is:</p>
  
  <pre><code>public void crossCountryCheckboxClicked(View view)
  {
      CheckBox crossCountryCheckBox = (CheckBox)findViewById(R.id.checkbox_cross_country);
      EditText crossCountryHoursTextBox = (EditText)findViewById(R.id.cross_country_hours);
      if (crossCountryCheckBox.isChecked())
      {
          crossCountryHoursTextBox.setVisibility(View.VISIBLE);
      }
      else
      {
          crossCountryHoursTextBox.setVisibility(View.GONE);
      }
  }
  </code></pre>
  
  <p>and the <code>crossCountryCheckboxClicked()</code> method is called by specifying the <code>android:onClick</code> attribute on the <code>CheckBox</code> element in the XML layout file.</p>
  
  <p>Here is the XML layout file:</p>
  
  <pre><code>&lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:custom="http://schemas.android.com/apk/res/logbook.app.activities"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" &gt;
  
  &lt;RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content" &gt;
  
      &lt;TextView
          android:id="@+id/flight_date"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content" /&gt;
  
      &lt;EditText
          android:id="@+id/aeroplane_type"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_below="@id/flight_date"
          android:hint="@string/aeroplane_type" /&gt;
  
      &lt;EditText
          android:id="@+id/aeroplane_registration"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_below="@id/aeroplane_type"
          android:hint="@string/aeroplane_registration" /&gt;
  
      &lt;EditText
          android:id="@+id/pilot_name"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_below="@id/aeroplane_registration"
          android:hint="@string/pilot_name" /&gt;
  
      &lt;EditText
          android:id="@+id/copilot_name"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_below="@id/pilot_name"
          android:hint="@string/copilot_name" /&gt;
  
      &lt;EditText
          android:id="@+id/from_aerodome"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_below="@id/copilot_name"
          android:hint="@string/from_aerodome" /&gt;
  
      &lt;EditText
          android:id="@+id/to_aerodome"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_below="@id/copilot_name"
          android:layout_toRightOf="@id/from_aerodome"
          android:hint="@string/to_aerodome" /&gt;
  
      &lt;EditText
          android:id="@+id/remarks"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_below="@id/from_aerodome"
          android:hint="@string/remarks" /&gt;
  
      &lt;Spinner
          android:id="@+id/aircraft_engine_type_spinner"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_below="@id/remarks" /&gt;
  
      &lt;Spinner
          android:id="@+id/time_of_day_spinner"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_below="@id/aircraft_engine_type_spinner" /&gt;
  
      &lt;Spinner
          android:id="@+id/pilot_role_spinner"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_below="@id/time_of_day_spinner" /&gt;
  
      &lt;TextView
          android:id="@+id/on_time"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_below="@id/pilot_role_spinner"
          android:hint="@string/on_time_hint" /&gt;
  
      &lt;TextView
          android:id="@+id/takeoff_time"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_below="@id/on_time"
          android:hint="@string/takeoff_time_hint" /&gt;
  
      &lt;TextView
          android:id="@+id/landing_time"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_below="@id/takeoff_time"
          android:hint="@string/landing_time_hint" /&gt;
  
      &lt;TextView
          android:id="@+id/off_time"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_below="@id/landing_time"
          android:hint="@string/off_time_hint" /&gt;
  
      &lt;Button
          android:id="@+id/button_record"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@id/off_time"
          android:onClick="recordTime"
          android:padding="5dp"
          android:text="@string/button_record" /&gt;
  
      &lt;Button
          android:id="@+id/button_reset"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@id/off_time"
          android:layout_toRightOf="@id/button_record"
          android:onClick="resetAllTimes"
          android:padding="5dp"
          android:text="@string/button_reset" /&gt;
  
      &lt;CheckBox
          android:id="@+id/checkbox_ifr"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/button_record"
          android:text="@string/checkbox_ifr"
          android:onClick="ifrCheckboxClicked" /&gt;
  
      &lt;CheckBox
          android:id="@+id/checkbox_cross_country"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/button_record"
          android:layout_toRightOf="@id/checkbox_ifr"
          android:text="@string/checkbox_cross_country"
          android:onClick="crossCountryCheckboxClicked" /&gt;
  
      &lt;Spinner
          android:id="@+id/ifr_type_spinner"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_below="@id/checkbox_ifr"
          android:visibility="gone" /&gt;
  
      &lt;TextView
          android:id="@+id/label_ifr_approaches"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@id/ifr_type_spinner"
          android:hint="@string/ifr_landings_label"
          android:visibility="gone" /&gt;
  
      &lt;logbook.app.custom.widgets.NumberSelector
          android:id="@+id/ifr_landings_selector"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@id/label_ifr_approaches"
          android:visibility="gone"
          custom:orientation="vertical" /&gt;
  
      &lt;EditText
          android:id="@+id/ifr_hours"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@id/ifr_landings_selector"
          android:hint="@string/ifr_hours_hint"
          android:inputType="number"
          android:visibility="gone" /&gt;
  
      &lt;EditText
          android:id="@+id/cross_country_hours"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@id/ifr_hours"
          android:hint="@string/cross_country_hours_hint"
          android:inputType="number"
          android:visibility="gone" /&gt;
  
      &lt;TextView
          android:id="@+id/label_takeoffs_landings"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@id/cross_country_hours"
          android:hint="@string/takeoffs_landings_label" /&gt;
  
      &lt;logbook.app.custom.widgets.NumberSelector
          android:id="@+id/landings_selector"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@id/label_takeoffs_landings"
          custom:orientation="horizontal" /&gt;
  
      &lt;Button
          android:id="@+id/button_create_log"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@id/landings_selector"
          android:onClick="createLog"
          android:padding="5dp"
          android:text="@string/button_create_log" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p></p>
  
  <p>How can I stop the <code>ScrollView</code> from scrolling to the top every time one of its children's visibilities is changed between <code>View.GONE</code> and <code>View.Visible</code>?</p>