0

I have a ScrollView with some TextViews/EditTexts in order to build a Register form.

When I click on my EditText, the ScrollView scroll as expected (EditText just above the softkeyboard).

But If I start typing some text in it, the ScrollView scroll at the top (EditText is covered by the keyboard).

If I remove the text I typed, the ScrollView scroll again at the good position.

Does someone already had this problem?

Here is my layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

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

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

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:weightSum="10"
                android:paddingTop="5dp"
                android:paddingBottom="5dp">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="5"
                    android:drawableLeft="@drawable/my_drawable"
                    android:drawablePadding="5dp"
                    android:text="Some text"
                    android:textStyle="bold" />

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="5"
                    android:orientation="vertical">

                    <Button
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:drawableLeft="@drawable/my_drawable_2"
                        android:text="My button"
                        android:textAllCaps="true" />

                    <EditText
                        android:background="@drawable/my_background"
                        android:padding="10dp"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="16dp"
                        android:hint="1234567896324"
                        android:imeOptions="actionDone"
                        android:inputType="number"
                        android:maxLength="19"
                        android:singleLine="true" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Explanation"
                        android:textColor="#d3d3d3"
                        android:textSize="12sp" />
                </LinearLayout>

            </LinearLayout>

        </LinearLayout>

    </ScrollView>

</LinearLayout>
Vte
  • 126
  • 9

2 Answers2

0

Well, I fix the problem by changing this:

android:windowSoftInputMode="adjustPan"

to this:

android:windowSoftInputMode="adjustResize"

Thanks to @Palejandro for the hint ;)

Vte
  • 126
  • 9
0

Try with this,it might helps you -

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:paddingBottom="5dp"
            android:paddingTop="5dp"
            android:weightSum="10">

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="5"
                android:drawablePadding="5dp"
                android:text="Some text"
                android:textStyle="bold"/>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="5"
                android:orientation="vertical">

                <Button
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:text="My button"
                    android:textAllCaps="true"/>

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="16dp"
                    android:hint="1234567896324"
                    android:imeOptions="actionDone"
                    android:inputType="number"
                    android:maxLength="19"
                    android:padding="10dp"
                    android:singleLine="true"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Explanation"
                    android:textColor="#d3d3d3"
                    android:textSize="12sp"/>
            </LinearLayout>

        </LinearLayout>

    </LinearLayout>

</ScrollView>