How do I stop the ScrollView from scrolling when the Spinner is selected?

I have a bunch of EditText, TextViews, Spinners and other components in my ScrollView. Now, when an item is selected from any Spinner, the Scrollview automatically scrolls and the first EditText gets focus.

How do I prevent those other views from being scrolled and scrolled?

I already tried android:descendantFocusability="beforeDescendants"

it but it didn't work "adjustPan"

either

Please, help

here is my xml code

<?xml version="1.0" encoding="utf-8"?>
<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">

    <include
        layout="@layout/appbar_registration"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"></include>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <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">

            <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" />

            <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" />
        </LinearLayout>

        <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">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:background="@drawable/rounded_corder_background">

                    <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" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:background="@drawable/rounded_corder_background">

                    <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 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" />

                </LinearLayout>

                <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">

                    <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" />

                    <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" />
                </LinearLayout>

                <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">

                    <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" />

                    <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" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:background="@drawable/rounded_corder_background">

                    <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" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:background="@drawable/rounded_corder_background">

                    <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" />

                </LinearLayout>

                <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">

                    <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" />

                </LinearLayout>

                <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">

                    <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" />
                </LinearLayout>

                <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">

                    <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" />

                    <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" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:background="@drawable/rounded_corder_background"
                    android:padding="5dp">

                    <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" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:background="@drawable/rounded_corder_background"
                    android:padding="5dp">


                    <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">

                        <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" />

                        <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" />
                    </RadioGroup>
                </LinearLayout>

                <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">

                    <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" />

                    <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" />
                </LinearLayout>

                <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">

                    <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" />

                    <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" />
                </LinearLayout>

                <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">

                    <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" />

                </LinearLayout>

                <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">

                    <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" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:background="@drawable/rounded_corder_background">

                    <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" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:background="@drawable/rounded_corder_background"
                    android:padding="5dp">

                    <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" />

                </LinearLayout>

            </LinearLayout>
        </ScrollView>

        <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">

            <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" />
        </LinearLayout>
    </RelativeLayout>


</LinearLayout>

      

+3


source to share


1 answer


Add to

 android:focusable="true"
 android:descendantFocusability="beforeDescendants"

      



in scrollview

0


source







All Articles