ScrollView does not work "Android Studio"

3

The truth is I have some basic knowledge in Android programming and others. I am making an application in Android Studio that tries to make a main screen so that a teacher and parent can register and log in. In the activity in which the parent registers I have many EditText and some RadioButton , and each of them in several LinearLayout s to maintain a better order. That's why I tried to put a ScrollView so you can go down the screen.

The problem is that I already implemented it, enclosing everything that I need to be Scroll and it does not work. I also declared the parent container as Scroll and it does not work either; when installing the APK on my Moto G to test it, the ScrollView does not work.

This is the XML File:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#3399cc"
    android:orientation="vertical"
    tools:context="joinder.proyecto.Main_formulario_padre">

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

        <LinearLayout
            android:id="@+id/linearLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="136dp"
            android:orientation="vertical"
            android:background="#ffffff">

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="10dp">

                <EditText
                    android:id="@+id/editText4"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:scrollbars="vertical"
                    android:focusable="true"
                    android:hint="Nombre :"
                    android:inputType="textPersonName"/>

            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="10dp">

                <EditText
                    android:id="@+id/editText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:scrollbars="vertical"
                    android:focusable="true"
                    android:hint="Apellido :"
                    android:inputType="textPersonName"/>

            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="10dp">

                <EditText
                    android:id="@+id/editText5"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:scrollbars="vertical"
                    android:focusable="true"
                    android:hint="Correo :"
                    android:inputType="textEmailAddress" />

            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="10dp">

                <EditText
                    android:id="@+id/editText6"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:scrollbars="vertical"
                    android:focusable="true"
                    android:hint="Telefono :"
                    android:inputType="phone" />

            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="10dp">

                <EditText
                    android:id="@+id/editText7"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:scrollbars="vertical"
                    android:focusable="true"
                    android:hint="Contraseña :"
                    android:inputType="textPassword" />

            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="10dp">

                <EditText
                    android:id="@+id/editText12"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:scrollbars="vertical"
                    android:focusable="true"
                    android:hint="Repetir Contraseña :"
                    android:inputType="textPassword" />

            </android.support.design.widget.TextInputLayout>

            <RadioGroup
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:scrollbars="vertical"
                android:gravity="center_vertical"
                android:padding="10dp">

                <RadioButton
                    android:id="@+id/radioButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Padre"
                    android:checked="false"
                    android:onClick="OnRadioButtonClicked"/>

                <RadioButton
                    android:id="@+id/radioButton2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Madre"
                    android:checked="false"
                    android:onClick="OnRadioButtonClicked"/>

                <RadioButton
                    android:id="@+id/radioButton3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Acudiente"
                    android:checked="false"
                    android:onClick="OnRadioButtonClicked"/>

            </RadioGroup>

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="15dp"
                android:scrollbars="vertical"
                android:textColor="#ffffff"
                android:background="@drawable/border_radius_2"/>

        </LinearLayout>

    </ScrollView>
</LinearLayout>

The ScrollView tag can already see that the platform automatically skips it; it's just before you start the first LinearLayout .

I hope you can help me.

    
asked by Rosyec Parrado 08.03.2017 в 15:03
source

3 answers

3

Assign the scrollbars property to your ScrollView so

 <ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical">

Also remove the marginTop that you put to the linearLayout inside the scrollView and add it as paddingTop to the main Layout and that works with it.

    
answered by 08.03.2017 / 17:52
source
2

The ScrollView can only have a child layout, so you must put all your content within a layout as LinearLayout for example and this within ScrollView

Example:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/your_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

         // ...

    </LinearLayout>

</ScrollView>
    
answered by 08.03.2017 в 15:17
0

This happens when we add fixed measures within the ScrollView in this case the margin:

android:layout_marginTop="136dp"

instead of a margin you can use padding

android:paddingTop="136dp"

or add a view to the layout.

The LinearLayout that contains the ScrollView is not necessary, you can omit it.

    
answered by 08.03.2017 в 18:52