键盘出现时 EditText 被隐藏

EditText gets hidden when Keyboard appears

因此,我正在使用代码的以下部分来获取输入,但是一旦键盘出现,文本就会隐藏在提示下,如 this gif 中所示。我该如何防止这种情况发生。

<LinearLayout
    android:layout_width="330dp"
    android:layout_height="0dp"
    android:layout_gravity="center"
    android:layout_weight="0.1"
    android:orientation="horizontal">

    <android.support.design.widget.TextInputLayout
        android:id="@+id/input_layout"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="0.8">

        <EditText
            style="@style/Widget.AppCompat.AutoCompleteTextView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="3dp"
            android:layout_marginRight="10dp"
            android:hint="Enter message here..." />
    </android.support.design.widget.TextInputLayout>

在你的清单中把它放在导致问题的activity

android:windowSoftInputMode="adjustPan"

请在 ScrollView

中添加您的布局
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
    android:layout_width="330dp"
    android:layout_height="0dp"
    android:layout_gravity="center"
    android:layout_weight="0.1"
    android:orientation="horizontal">

    <android.support.design.widget.TextInputLayout
        android:id="@+id/input_layout"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="0.8">

        <EditText
            style="@style/Widget.AppCompat.AutoCompleteTextView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="3dp"
            android:layout_marginRight="10dp"
            android:hint="Enter message here..." />
    </android.support.design.widget.TextInputLayout>
    </LinearLayout>
    </ScrollView>

并在 AndroidManifest.xml 中将此代码添加到您的 activity

<activity android:name=".ActivityName"
    android:windowSoftInputMode="adjustResize">

设置高度 wrap_content 是导致问题的原因。 在 linearlayout 中设置高度并在 autocompletetextview 中使用 match_parent

如果不需要,请删除 layout_weight