title: How to stop ScrollView from scrolling up when a Spinner item is selected?
body: <p>I have a bunch of EditText, TextViews, Spinners and Other components in my ScrollView, Now what happens is, when i selected an item from any Spinner, the Scrollview scrolls up automatically and the first EditText gets the focus.</p>
  
  <p>How to prevent these otherviews getting focus and ScrollView scrolling up?</p>
  
  <p>I have already tried <code>android:descendantFocusability="beforeDescendants"</code> but it did not work <code>"adjustPan"</code> also not working </p>
  
  <p>Please help</p>
  
  <p>here is my xml code</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@color/screen_background"
      android:orientation="vertical"&gt;
  
      &lt;include
          layout="@layout/appbar_registration"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"&gt;&lt;/include&gt;
  
      &lt;RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
  
          &lt;LinearLayout
              android:id="@+id/linear"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_alignParentTop="true"
              android:gravity="center"
              android:orientation="vertical"&gt;
  
              &lt;TextView
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:gravity="center"
                  android:text="SIGN UP"
                  android:textColor="@color/background_color"
                  android:textSize="30sp" /&gt;
  
              &lt;TextView
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:gravity="center"
                  android:text="Create an account"
                  android:textColor="@color/registration_text_gray" /&gt;
          &lt;/LinearLayout&gt;
  
          &lt;ScrollView
              android:id="@+id/scrollview"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_above="@+id/buttonlinear"
              android:layout_below="@+id/linear"
              android:layout_marginBottom="15dp"
              android:layout_marginLeft="15dp"
              android:layout_marginRight="15dp"
              android:fillViewport="true"
              android:scrollbars="none"&gt;
  
              &lt;LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_marginBottom="5dp"
                  android:orientation="vertical"&gt;
  
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_marginTop="5dp"
                      android:background="@drawable/rounded_corder_background"&gt;
  
                      &lt;EditText
                          android:id="@+id/registration_edt_name"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_weight="1"
                          android:ems="10"
                          android:hint="Name"
                          android:inputType="textCapWords"
                          android:lines="1"
                          android:paddingLeft="10dp"
                          android:paddingRight="10dp"
                          android:singleLine="true"
                          android:textColor="@color/registration_hint_color"
                          android:textColorHint="@color/registration_hint_color" /&gt;
  
                  &lt;/LinearLayout&gt;
  
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_marginTop="5dp"
                      android:background="@drawable/rounded_corder_background"&gt;
  
                      &lt;EditText
                          android:id="@+id/registration_edt_father_name"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_weight="1"
                          android:ems="10"
                          android:hint="Father's Name"
                          android:inputType="textCapWords"
                          android:lines="1"
                          android:paddingLeft="10dp"
                          android:paddingRight="10dp"
                          android:singleLine="true"
                          android:textColor="@color/registration_hint_color"
                          android:textColorHint="@color/registration_hint_color" /&gt;
  
                  &lt;/LinearLayout&gt;
  
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="40dp"
                      android:layout_marginBottom="5dp"
                      android:layout_marginTop="5dp"
                      android:background="@drawable/rounded_corder_background"
                      android:orientation="horizontal"
                      android:weightSum="10"&gt;
  
                      &lt;Spinner
                          android:id="@+id/registration_spnr_country"
                          android:layout_width="0dp"
                          android:layout_height="match_parent"
                          android:layout_weight="9.5"
                          android:background="@android:color/transparent" /&gt;
  
                      &lt;ImageView
                          android:id="@+id/registration_img_country"
                          android:layout_width="wrap_content"
                          android:layout_height="match_parent"
                          android:layout_gravity="center"
                          android:layout_weight="0.5"
  
                          android:src="@drawable/ic_spinner_arrow" /&gt;
                  &lt;/LinearLayout&gt;
  
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="40dp"
                      android:layout_marginBottom="5dp"
                      android:layout_marginTop="5dp"
                      android:background="@drawable/rounded_corder_background"
                      android:orientation="horizontal"
                      android:weightSum="10"&gt;
  
                      &lt;Spinner
                          android:id="@+id/registration_spnr_state"
                          android:layout_width="0dp"
                          android:layout_height="match_parent"
                          android:layout_weight="9.5"
                          android:background="@android:color/transparent"
                          android:clickable="false" /&gt;
  
                      &lt;ImageView
                          android:id="@+id/registration_img_state"
                          android:layout_width="wrap_content"
                          android:layout_height="match_parent"
                          android:layout_gravity="center"
                          android:layout_weight="0.5"
                          android:clickable="false"
                          android:src="@drawable/ic_spinner_arrow" /&gt;
                  &lt;/LinearLayout&gt;
  
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_marginTop="5dp"
                      android:background="@drawable/rounded_corder_background"&gt;
  
                      &lt;EditText
                          android:id="@+id/registration_edt_district"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_weight="1"
                          android:ems="10"
  
                          android:hint="District"
                          android:inputType="textCapWords"
                          android:lines="1"
                          android:paddingLeft="10dp"
                          android:paddingRight="10dp"
                          android:singleLine="true"
                          android:textColor="@color/registration_hint_color"
                          android:textColorHint="@color/registration_hint_color" /&gt;
  
                  &lt;/LinearLayout&gt;
  
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_marginTop="5dp"
                      android:background="@drawable/rounded_corder_background"&gt;
  
                      &lt;EditText
                          android:id="@+id/registration_edt_city_village"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_weight="1"
                          android:ems="10"
  
                          android:hint="City / Village"
                          android:inputType="textCapWords"
                          android:lines="1"
                          android:paddingLeft="10dp"
                          android:paddingRight="10dp"
                          android:singleLine="true"
                          android:textColor="@color/registration_hint_color"
                          android:textColorHint="@color/registration_hint_color" /&gt;
  
                  &lt;/LinearLayout&gt;
  
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_marginBottom="5dp"
                      android:layout_marginTop="5dp"
                      android:background="@drawable/rounded_corder_background"&gt;
  
                      &lt;EditText
                          android:id="@+id/registration_edt_mobile"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_weight="1"
                          android:ems="10"
  
                          android:hint="Mobile"
                          android:inputType="phone"
                          android:lines="1"
                          android:maxLength="10"
                          android:paddingLeft="10dp"
                          android:paddingRight="10dp"
                          android:singleLine="true"
                          android:textColor="@color/registration_hint_color"
                          android:textColorHint="@color/registration_hint_color" /&gt;
  
                  &lt;/LinearLayout&gt;
  
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_marginBottom="5dp"
                      android:layout_marginTop="5dp"
                      android:background="@drawable/rounded_corder_background"&gt;
  
                      &lt;AutoCompleteTextView
                          android:id="@+id/registration_edt_email"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_weight="1"
                          android:ems="10"
  
                          android:hint="Email"
                          android:inputType="textEmailAddress"
                          android:lines="1"
                          android:paddingLeft="10dp"
                          android:paddingRight="10dp"
                          android:singleLine="true"
                          android:textColor="@color/registration_hint_color"
                          android:textColorHint="@color/registration_hint_color" /&gt;
                  &lt;/LinearLayout&gt;
  
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="40dp"
                      android:layout_marginBottom="5dp"
                      android:layout_marginTop="5dp"
                      android:background="@drawable/rounded_corder_background"
                      android:orientation="horizontal"
                      android:weightSum="10"&gt;
  
                      &lt;Spinner
                          android:id="@+id/registration_spnr_last_exam_passed"
                          android:layout_width="0dp"
                          android:layout_height="match_parent"
                          android:layout_weight="9.5"
                          android:background="@android:color/transparent"
                          android:entries="@array/last_exam_passed" /&gt;
  
                      &lt;ImageView
                          android:id="@+id/registration_img_last_exam_passed"
                          android:layout_width="wrap_content"
                          android:layout_height="match_parent"
                          android:layout_gravity="center"
                          android:layout_weight="0.5"
                          android:src="@drawable/ic_spinner_arrow" /&gt;
                  &lt;/LinearLayout&gt;
  
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_marginTop="5dp"
                      android:background="@drawable/rounded_corder_background"
                      android:padding="5dp"&gt;
  
                      &lt;TextView
                          android:id="@+id/registration_txt_date_of_birth"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:gravity="left"
                          android:lines="1"
                          android:padding="5dp"
                          android:text="Date of Birth"
                          android:textAppearance="?android:attr/textAppearanceMedium"
                          android:textColor="@color/registration_hint_color" /&gt;
                  &lt;/LinearLayout&gt;
  
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_marginTop="5dp"
                      android:background="@drawable/rounded_corder_background"
                      android:padding="5dp"&gt;
  
  
                      &lt;RadioGroup
                          android:id="@+id/radioGroup"
                          android:layout_width="fill_parent"
                          android:layout_height="wrap_content"
                          android:orientation="horizontal"
                          android:paddingLeft="40dp"
                          android:paddingRight="40dp"
                          android:weightSum="1"&gt;
  
                          &lt;RadioButton
                              android:id="@+id/radioButton"
                              android:layout_width="0dp"
                              android:layout_height="wrap_content"
                              android:layout_weight="0.5"
                              android:buttonTint="@color/colorPrimary"
                              android:checked="false"
                              android:text="Male"
                              android:textColor="@color/registration_hint_color" /&gt;
  
                          &lt;RadioButton
                              android:id="@+id/radioButton2"
                              android:layout_width="0dp"
                              android:layout_height="wrap_content"
                              android:layout_weight="0.5"
                              android:buttonTint="@color/colorPrimary"
                              android:checked="false"
                              android:text="Female"
                              android:textColor="@color/registration_hint_color" /&gt;
                      &lt;/RadioGroup&gt;
                  &lt;/LinearLayout&gt;
  
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="40dp"
                      android:layout_marginBottom="5dp"
                      android:layout_marginTop="5dp"
                      android:background="@drawable/rounded_corder_background"
                      android:orientation="horizontal"
                      android:weightSum="10"&gt;
  
                      &lt;Spinner
                          android:id="@+id/registration_spnr_cast"
                          android:layout_width="0dp"
                          android:layout_height="match_parent"
                          android:layout_weight="9.5"
                          android:background="@android:color/transparent"
                          android:entries="@array/cast" /&gt;
  
                      &lt;ImageView
                          android:id="@+id/registration_img_cast"
                          android:layout_width="wrap_content"
                          android:layout_height="match_parent"
                          android:layout_gravity="center"
                          android:layout_weight="0.5"
                          android:src="@drawable/ic_spinner_arrow" /&gt;
                  &lt;/LinearLayout&gt;
  
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="40dp"
                      android:layout_marginBottom="5dp"
                      android:layout_marginTop="5dp"
                      android:background="@drawable/rounded_corder_background"
                      android:orientation="horizontal"
                      android:weightSum="10"&gt;
  
                      &lt;Spinner
                          android:id="@+id/registration_spnr_religion"
                          android:layout_width="0dp"
                          android:layout_height="match_parent"
                          android:layout_weight="9.5"
                          android:background="@android:color/transparent"
                          android:entries="@array/religion" /&gt;
  
                      &lt;ImageView
                          android:id="@+id/registration_img_religion"
                          android:layout_width="wrap_content"
                          android:layout_height="match_parent"
                          android:layout_gravity="center"
                          android:layout_weight="0.5"
                          android:src="@drawable/ic_spinner_arrow" /&gt;
                  &lt;/LinearLayout&gt;
  
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_marginBottom="5dp"
                      android:layout_marginTop="5dp"
                      android:background="@drawable/rounded_corder_background"&gt;
  
                      &lt;EditText
  
                          android:id="@+id/registration_edt_password"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_weight="1"
                          android:ems="10"
  
                          android:fontFamily="sans-serif"
                          android:hint="Password"
                          android:inputType="textPassword"
                          android:lines="1"
                          android:maxLength="18"
                          android:paddingLeft="10dp"
                          android:paddingRight="10dp"
                          android:singleLine="true"
                          android:textColor="@color/registration_hint_color"
                          android:textColorHint="@color/registration_hint_color" /&gt;
  
                  &lt;/LinearLayout&gt;
  
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_marginBottom="5dp"
                      android:layout_marginTop="5dp"
                      android:background="@drawable/rounded_corder_background"&gt;
  
                      &lt;EditText
                          android:id="@+id/registration_edt_confirm_password"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_weight="1"
                          android:ems="10"
  
                          android:fontFamily="sans-serif"
                          android:hint="Confirm Password"
                          android:inputType="textPassword"
                          android:lines="1"
                          android:maxLength="18"
                          android:paddingLeft="10dp"
                          android:paddingRight="10dp"
                          android:singleLine="true"
                          android:textColor="@color/registration_hint_color"
                          android:textColorHint="@color/registration_hint_color" /&gt;
  
                  &lt;/LinearLayout&gt;
  
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_marginTop="5dp"
                      android:background="@drawable/rounded_corder_background"&gt;
  
                      &lt;EditText
                          android:id="@+id/registration_edt_parent_code"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_weight="1"
                          android:ems="10"
  
                          android:hint="Parent Code (Optional)"
                          android:inputType="textCapWords"
                          android:lines="1"
                          android:paddingLeft="10dp"
                          android:paddingRight="10dp"
                          android:singleLine="true"
                          android:textColor="@color/registration_hint_color"
                          android:textColorHint="@color/registration_hint_color" /&gt;
  
                  &lt;/LinearLayout&gt;
  
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_marginTop="5dp"
                      android:background="@drawable/rounded_corder_background"
                      android:padding="5dp"&gt;
  
                      &lt;CheckBox
                          android:id="@+id/registration_chk_agreement"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:buttonTint="@color/colorPrimary"
                          android:lines="1"
                          android:padding="10dp"
                          android:text="I Agree to the Terms And Conditions"
                          android:textAppearance="?android:attr/textAppearanceMedium"
                          android:textColor="@color/registration_hint_color" /&gt;
  
                  &lt;/LinearLayout&gt;
  
              &lt;/LinearLayout&gt;
          &lt;/ScrollView&gt;
  
          &lt;LinearLayout
              android:id="@+id/buttonlinear"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_alignParentBottom="true"
              android:layout_marginLeft="15dp"
              android:layout_marginRight="15dp"
              android:orientation="vertical"&gt;
  
              &lt;Button
                  android:id="@+id/registration_btn_sign_up"
                  style="?android:textAppearanceSmall"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_marginBottom="16dp"
                  android:background="@color/colorPrimary"
                  android:lines="1"
                  android:singleLine="true"
                  android:text="Submit"
                  android:textColor="@color/white"
                  android:textStyle="bold" /&gt;
          &lt;/LinearLayout&gt;
      &lt;/RelativeLayout&gt;
  
  
  &lt;/LinearLayout&gt;
  </code></pre>