Search code examples
androidandroid-scrollviewandroid-relativelayout

scrollview doesn't scroll android in RelativeLayout


I am really new in using the scrollView so please be patient with me:)

I am trying to make an whole view of a scrollView but the scrollView doesn't scroll.

Here is my xml code :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/general_form_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bg"
    android:fillViewport="true"
    android:orientation="vertical" >

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

        <RelativeLayout
            android:id="@+id/form_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true"
            android:padding="10dp" >

            <WebView
                android:id="@+id/myWebView"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true" />

            <EditText
                android:id="@+id/FirstNameRegister"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/myWebView"
                android:autoText="false"
                android:editable="true"
                android:ems="10"
                android:hint="Full name"
                android:imeOptions="flagNoExtractUi"
                android:selectAllOnFocus="true"
                android:singleLine="true" />

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                android:text="+" />

            <ProgressBar
                android:id="@+id/myProgressBar"
                style="?android:attr/progressBarStyleLarge"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/myWebView"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="84dp" />

            <EditText
                android:id="@+id/PhoneRegister"
                android:layout_width="205dp"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/textView1"
                android:layout_below="@+id/EmailRegister"
                android:autoText="false"
                android:editable="true"
                android:ems="10"
                android:hint="phone"
                android:imeOptions="flagNoExtractUi"
                android:inputType="phone"
                android:selectAllOnFocus="true"
                android:singleLine="true" />

            <EditText
                android:id="@+id/EmailRegister"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@+id/myWebView"
                android:layout_alignBottom="@+id/myWebView"
                android:layout_alignParentRight="true"
                android:layout_marginRight="23dp"
                android:autoText="false"
                android:editable="true"
                android:ems="10"
                android:hint="Email"
                android:imeOptions="flagNoExtractUi"
                android:inputType="textEmailAddress"
                android:selectAllOnFocus="true"
                android:singleLine="true" />

            <EditText
                android:id="@+id/DialZonePhoneRegister"
                android:layout_width="55dp"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@+id/myWebView"
                android:layout_alignBottom="@+id/myWebView"
                android:layout_alignLeft="@+id/textView1"
                android:autoText="false"
                android:editable="true"
                android:ems="10"
                android:hint="3344"
                android:imeOptions="flagNoExtractUi"
                android:inputType="number"
                android:selectAllOnFocus="true"
                android:singleLine="true" >
            </EditText>
        </RelativeLayout>
    </ScrollView>

    <Button
        android:id="@+id/SubmitRegisterButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/EmailRegister"
        android:layout_centerHorizontal="true"
        android:background="@drawable/s" />

</RelativeLayout>

Please help me with it:)


Solution

  • You have to change the layout params of form_layout to be like this :

     android:id="@+id/form_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fillViewport="true"
            android:padding="10dp" >
    

    In other words, the layout height have to be wrap_content. If the height is set to match_parent, then it will fill the height of the screen from parent layout and it will not cover the extra elements that are located above the screen height.