键盘隐藏留空 space

Keyboard hide leaves empty blank space

我有一个问题,比如在我的键盘弹出并隐藏之后,键盘所在的位置是空的 space。 ScrollView 里面只有几个组件。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/activity_horizontal_margin"
    android:orientation="vertical">

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

        <EditText
            android:id="@+id/state"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/hint_state" />
    </android.support.design.widget.TextInputLayout>

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

        <EditText
            android:id="@+id/district"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/hint_district" />

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

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

        <AutoCompleteTextView
            android:id="@+id/police_station"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/hint_station" />

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

    <include
        android:id="@+id/vehicle_type"
        layout="@layout/template_cascading_spinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp" />

    <include
        android:id="@+id/vehicle_manufacturer"
        layout="@layout/template_cascading_spinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp" />

    <include
        android:id="@+id/vehicle_model"
        layout="@layout/template_cascading_spinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp" />

    <include
        android:id="@+id/registration_no"
        layout="@layout/template_registration_no"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp" />

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

        <AutoCompleteTextView
            android:id="@+id/engine_no"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/hint_station" />

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

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

        <AutoCompleteTextView
            android:id="@+id/chassis_no"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/hint_station" />

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

    <include
        android:id="@+id/capture_image"
        layout="@layout/template_image_control"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dp" />

</LinearLayout>

</ScrollView>

及其屏幕截图。

我还没有找到发生这种情况的任何原因。任何帮助都会有所帮助。

注意: 我用 Google 搜索了足够多的解决方案,但在 styles.xml 中添加 windowBackground 没有帮助。而且我找不到使用它的正当理由。

我也试过不加TextInputLayout。但是结果是一样的。

发生在 Android 的所有版本中。

我脑袋破了之后想通了。这是因为我在 activity 中使用了 android.support.design.widget.CoordinatorLayout

上面的xml是附在MainActivity上的片段。在 Main Activity XML 中,我有 CoordinateLayout 作为 parent。我认为将 CoordinateLayoutScrollView.

一起使用可能存在一些错误

将其更改为 LinearLayout 暂时解决了我的问题。