0

I have an activity with a form. I put all views in a ScrollView because when the keyboard opens, I would scroll through the fields.

When the keyboard opens, the first field goes over the top of the ScrollView and becomes unreachable.

This is the layout:

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

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:orientation="vertical">

    <EditText
        android:id="@+id/username"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:hint="Username"
        android:inputType="text|textEmailAddress"
        android:singleLine="true" />

    <EditText
        android:id="@+id/password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:hint="Password"
        android:inputType="textPassword"
        android:singleLine="true" />

    <EditText
        android:id="@+id/password1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:hint="@string/repeat_password"
        android:inputType="textPassword"
        android:singleLine="true" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="@string/gender" />

        <RadioGroup
            android:id="@+id/gender"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingLeft="5dp">

            <RadioButton
                android:id="@+id/male"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true"
                android:text="M" />

            <RadioButton
                android:id="@+id/female"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="F" />
        </RadioGroup>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="@string/age" />

        <EditText
            android:id="@+id/age"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number"
            android:paddingLeft="5dp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="@string/education" />

        <Spinner
            android:id="@+id/education"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="5dp" />
    </LinearLayout>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:onClick="salva"
        android:text="@string/save" />
</LinearLayout>

</ScrollView>

This is the activity definition in the manifest:

<activity
        android:name=".activities.SignUpActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/title_activity_sign_up">
</activity>

This is a screenshot. The username field is unreachable! (look at the scrollbar on the right) Screenshot

Xan
  • 74,770
  • 16
  • 179
  • 206
fran
  • 1,119
  • 1
  • 10
  • 27

3 Answers3

1

Use following in your App Manifest

 android:windowSoftInputMode="stateHidden|adjustPan" 

For more details you can visit here

http://developer.android.com/guide/topics/manifest/activity-element.html

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

In your activity manifest entry add this:

android:windowSoftInputMode="stateVisible|adjustPan".

ajacian81
  • 7,419
  • 9
  • 51
  • 64
0

I've found the solution. The problem was this line:

android:layout_gravity="center"

I just removed it from the layout file. The manifest was correct.

fran
  • 1,119
  • 1
  • 10
  • 27