【问题标题】:EditText gets hidden when Keyboard appears键盘出现时 EditText 被隐藏
【发布时间】:2018-06-22 05:57:35
【问题描述】:

因此,我使用以下代码部分来获取输入,但一旦出现键盘,文本就会隐藏在提示下,如 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>

【问题讨论】:

  • 可以添加完整的布局代码吗?
  • 你做错了。如果您发布整个 xml 文件将会很有帮助。
  • 发布您的清单代码以及布局上方的哪个Activity?

标签: android xml android-edittext textinputlayout


【解决方案1】:

在您的清单中将其放入导致问题的活动中

android:windowSoftInputMode="adjustPan"

【讨论】:

    【解决方案2】:

    请将您的布局添加到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 android:name=".ActivityName"
        android:windowSoftInputMode="adjustResize">
    

    【讨论】:

      【解决方案3】:

      设置高度 wrapcontent 会导致问题。 在 linearlayout 中设置高度并在 autocompletetextview 中使用 matchparent

      如果不需要,删除 layout_weight

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-08-20
        • 1970-01-01
        • 2013-01-12
        • 1970-01-01
        • 2014-08-07
        • 1970-01-01
        • 2014-12-13
        相关资源
        最近更新 更多