Мягкая клавиатура не запускает прокрутку в ScrollView

Я знаю, что здесь на SO много вопросов относительно проблемы с EditText, показывая мягкую клавиатуру ввода и то, что у вас должно быть в манифесте (adjustPan или AdjustResize).

Я прочитал много вопросов и ответов здесь, но не смог решить свою проблему.

На самом деле это довольно просто: у меня есть действие входа в систему, и все содержимое помещается на один экран, когда клавиатура НЕ отображается. В нижней части этого действия входа у меня есть кнопка, которая всегда должна быть внизу. При фокусировке на одном EditText клавиатура появляется и скрывает некоторые вещи. Когда клавиатура поднята, я хотел бы иметь возможность прокручивать вниз, но не могу.

  • Я установил действие «adjustPan» в манифесте.

Вот два изображения, без клавиатуры и с клавиатурой:

введите здесь описание изображениявведите здесь описание изображения

Теперь, когда клавиатура поднята, я хотел бы прокрутить вниз, чтобы увидеть кнопки (желтые и внизу). Я не могу этого сделать.

Если я вместо этого установлю в манифесте значение «adjustRezise», я получу еще один нежелательный эффект, который можно увидеть здесь:

введите здесь описание изображения

Кнопка внизу не находится «поверх» других вещей, но я не могу прокручивать (чтобы можно было просмотреть кнопку «Войти»).

Первый вопрос: почему не работает прокрутка с «adjustPan» и когда клавиатура что-то скрывает? Это разумная вещь, которую я бы сказал.

Вот мой XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout6"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/taxibg3"
    android:orientation="vertical" >

    <ScrollView
        android:id="@+id/ScrollView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/login_logoBarInclude"
        android:fillViewport="true"
        android:orientation="vertical" >

        <RelativeLayout
            android:id="@+id/login_form"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <LinearLayout
                android:id="@+id/iv1"
                android:layout_width="240dp"
                android:layout_height="280dp"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="5dp"
                android:background="@drawable/login_square_adapted"
                android:orientation="vertical"
                android:paddingTop="15dp" >

                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:text="@string/vehicleLogin"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#ffffff" />

                <FrameLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="3dp"
                    android:layout_marginRight="3dp"
                    android:layout_marginTop="10dp" >

                    <include layout="@layout/menu_divider_horizontal" >
                    </include>
                </FrameLayout>

                <RelativeLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="30dp"
                    android:layout_marginRight="30dp"
                    android:layout_marginTop="35dp"
                    android:gravity="center_horizontal"
                    android:orientation="vertical" >

                    <EditText
                        android:id="@+id/login_carNumber"
                        style="@style/EditTextDark"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_toRightOf="@+id/login_car_icon"
                        android:hint="@string/prompt_carNumber"
                        android:inputType="phone"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textCursorDrawable="@null" >

                        <requestFocus />
                    </EditText>

                    <ImageView
                        android:id="@+id/login_car_icon"
                        android:layout_width="40dp"
                        android:layout_height="40dp"
                        android:src="@drawable/user" />

                    <EditText
                        android:id="@+id/login_password"
                        style="@style/EditTextDark"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@id/login_carNumber"
                        android:layout_marginTop="10dp"
                        android:layout_toRightOf="@+id/login_lock_icon"
                        android:hint="@string/prompt_password"
                        android:inputType="phone"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textCursorDrawable="@null" >
                    </EditText>

                    <ImageView
                        android:id="@+id/login_lock_icon"
                        android:layout_width="40dp"
                        android:layout_height="40dp"
                        android:layout_alignTop="@id/login_password"
                        android:layout_below="@id/login_car_icon"
                        android:src="@drawable/lock" />

                    <Button
                        android:id="@+id/sign_in_button"
                        android:layout_width="fill_parent"
                        android:layout_height="40dp"
                        android:layout_alignParentBottom="true"
                        android:layout_centerHorizontal="true"
                        android:layout_marginBottom="10dp"
                        android:background="@drawable/button_rounded"
                        android:gravity="center_horizontal"
                        android:paddingTop="5dp"
                        android:text="@string/action_sign_in_short"
                        android:textColor="#000000" />
                </RelativeLayout>
            </LinearLayout>
        </RelativeLayout>
    </ScrollView>


    <Button
        android:id="@+id/quit_app_button"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="@string/action_exit_app" />

</RelativeLayout>

======= РЕДАКТИРОВАТЬ ==========

Итак, я изменил раскладку по предложению Джозефа, но теперь "высота очень большая", хотя причин для этого нет, т.е. кнопка в конце находится "далеко вниз", поэтому нужно прокручивать "далеко вниз" ", чтобы увидеть его, вместо того, чтобы находиться внизу экрана. Надеюсь, вы понимаете, что я имею в виду:

Обратите внимание на полосу прокрутки справа, и кнопка не видна, так как она находится далеко внизу

*Обратите внимание на полосу прокрутки справа, и кнопка не видна, так как она находится «далеко внизу». Кроме того, фон растянут, так что это будет означать, что RelativeLayout, называемый «linearLayoyt6» (да, сбивает с толку), по какой-то причине расширяется вниз... *

Я попытался установить высоту на фиксированный dp для ScrollView и макетов ниже, но ничего не помогло. А XML такой:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScrollView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <RelativeLayout
        android:id="@+id/linearLayout6"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/taxibg3"
        android:orientation="vertical" >

        <RelativeLayout
            android:id="@+id/login_form"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            >

            <LinearLayout
                android:id="@+id/iv1"
                android:layout_width="240dp"
                android:layout_height="280dp"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="25dp"
                android:background="@drawable/login_square_adapted"
                android:orientation="vertical"
                android:paddingBottom="0dp"
                android:paddingLeft="0dp"
                android:paddingRight="0dp"
                android:paddingTop="15dp" >

                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:text="@string/vehicleLogin"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="#ffffff" />

                <FrameLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="3dp"
                    android:layout_marginRight="3dp"
                    android:layout_marginTop="10dp" >

                    <include layout="@layout/menu_divider_horizontal" >
                    </include>
                </FrameLayout>

                <RelativeLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="30dp"
                    android:layout_marginRight="30dp"
                    android:layout_marginTop="35dp"
                    android:gravity="center_horizontal"
                    android:orientation="vertical" >

                    <EditText
                        android:id="@+id/login_carNumber"
                        style="@style/EditTextDark"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_toRightOf="@+id/login_car_icon"
                        android:hint="@string/prompt_carNumber"
                        android:inputType="phone"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textCursorDrawable="@null" >

                        <requestFocus />
                    </EditText>

                    <ImageView
                        android:id="@+id/login_car_icon"
                        android:layout_width="40dp"
                        android:layout_height="40dp"
                        android:src="@drawable/user" />

                    <EditText
                        android:id="@+id/login_password"
                        style="@style/EditTextDark"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@id/login_carNumber"
                        android:layout_marginTop="10dp"
                        android:layout_toRightOf="@+id/login_lock_icon"
                        android:hint="@string/prompt_password"
                        android:inputType="phone"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textCursorDrawable="@null" >
                    </EditText>

                    <ImageView
                        android:id="@+id/login_lock_icon"
                        android:layout_width="40dp"
                        android:layout_height="40dp"
                        android:layout_alignTop="@id/login_password"
                        android:layout_below="@id/login_car_icon"
                        android:src="@drawable/lock" />
                </RelativeLayout>

                <FrameLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_marginTop="30dp"
                    android:background="@drawable/login_square_half"
                    android:padding="0dp" >

                    <Button
                        android:id="@+id/sign_in_button"
                        android:layout_width="120dp"
                        android:layout_height="40dp"
                        android:layout_gravity="center_vertical|center_horizontal"
                        android:background="@drawable/button_rounded"
                        android:gravity="center_horizontal"
                        android:text="@string/action_sign_in_short"
                        android:textColor="#000000" />
                </FrameLayout>
            </LinearLayout>
        </RelativeLayout>

        <Button
            android:id="@+id/quit_app_button"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:text="@string/action_exit_app" />
    </RelativeLayout>

</ScrollView>

person Ted    schedule 13.01.2013    source источник


Ответы (1)


Попробуйте изменить resizeMode на adjustResize и переместить ScrollView изнутри вашего RelativeLayout linearLayout6 наружу и установить layout_height из RelativeLayout на wrap_content.

person Joseph Earl    schedule 13.01.2013
comment
Спасибо, но это не сработало. Весь экран теперь расширился вниз, намного больше, чем реальный экран, вещи перекрываются и всякие странные вещи. К сожалению, ошибки времени выполнения тоже :-( - person Ted; 14.01.2013
comment
На самом деле, это могло бы сработать, но проблема в том, что указано выше - область вниз теперь очень большая, т.е. даже с самого начала я могу прокрутить фааар вниз, где кнопка. Но я не могу понять, почему внизу так много места... См. мой РЕДАКТИРОВАТЬ выше. - person Ted; 14.01.2013