android edittext在键盘打开时变得部分可见

标签 android android-linearlayout

我在打开键盘时遇到问题,编辑文本部分显示,例如不是完整 View 。

截图:

enter image description here

这是布局代码:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/lightgreen"
    android:fillViewport="true"
    android:padding="20dp" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/lightgreen"
        android:orientation="vertical" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/str_mobilenumber"
            android:textSize="16sp" />

        <EditText
            android:id="@+id/reg_mobile"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="phone" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/str_password"
            android:textSize="16sp" />

        <EditText
            android:id="@+id/reg_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/str_password_confirm"
            android:textSize="16sp" />

        <EditText
            android:id="@+id/reg_password_confirm"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/str_fullname"
            android:textSize="16sp" />

        <EditText
            android:id="@+id/reg_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            tools:ignore="TextFields" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/str_email"
            android:textSize="16sp" />

        <EditText
            android:id="@+id/reg_email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textEmailAddress" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="3dp"
            android:text="@string/str_city"
            android:textSize="16sp" />

        <Spinner
            android:id="@+id/reg_city"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:entries="@array/cities_array"
            android:prompt="@string/str_city" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/str_zip"
            android:textSize="16sp" />

        <EditText
            android:id="@+id/reg_zip"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:inputType="phone" />

        <Button
            android:id="@+id/btnRegister"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:onClick="actionRegister"
            android:text="@string/str_register" />
    </LinearLayout>

</ScrollView>

同样的问题发生在任何编辑文本字段上,当键盘打开时,它没有完全显示。有什么办法可以避免这个问题吗?

谢谢

最佳答案

问题是您的布局和键盘没有足够的空间。您可以滚动查看以防止出现此问题。有两种方法可以做到这一点:

“调整调整大小”

Activity 的主窗口始终会调整大小以为屏幕上的软键盘腾出空间。

“调整平移”

Activity 的主窗口不会调整大小来为软键盘腾出空间。相反,窗口的内容会自动平移,以便当前焦点永远不会被键盘遮挡,用户始终可以看到他们正在输入的内容。这通常不如调整大小可取,因为用户可能需要关闭软键盘才能到达窗口的遮挡部分并与之交互。

您应该将此行添加到 manifest.xml 中的 Activity 标记中

<activity android:windowSoftInputMode="adjustResize"> </activity>

关于android edittext在键盘打开时变得部分可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27471397/

相关文章:

android - 更换电脑时是否需要更改 Google Maps API key ?

java - 在 Eclipse 中将 Android 项目转换为 'regular' Java 项目?

android - Unity 如何调用 Activity 的 onNewIntent()

android Intent setFlags 问题

android - 如何创建具有 4 列的 TableLayout?

android - 在 Android 中将城市作为标记传递

android - 手动定义布局参数,意味着我想使用我的值来定义布局的边界

android - 如何在选项卡式应用程序中替换 LinearLayout 下的 fragment

java - 如何在 ScrollView 和 LinearLayout 中居中

android - RTL 不适用于布局