【问题标题】:EditText goes out of the screen sometimes when virtual keyboard shows up当虚拟键盘出现时,EditText 有时会离开屏幕
【发布时间】:2012-01-07 03:12:55
【问题描述】:

我正在为 Android 开发一个应用程序。

我有一个简单的布局。一个 CheckBox,一个 Spinner 和一个 Button 在顶部,一个两行 EditText 在底部,当 CheckBox 被选中时显示,另一个 EditText 覆盖中间的其余空间。

问题是当我在大的 EditText 上书写时,有时布局会超出屏幕顶部,结果我看不到我在写什么。

作为一种解决方案,我可以将我的布局设置为在键盘显示时调整大小(在 manifest.xml 上使用 android:windowSoftInputMode="adjustResize")但这并不好,因为我不希望 2 个 EditTexts 共享屏幕上的剩余空间。

我的布局代码如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <Button android:id="@+id/button"
        android:text="Push"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" 
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"/>
    <CheckBox android:id="@+id/check_box"
        android:text="Check"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true" />
    <Spinner android:id="@+id/spinner"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />   
    <EditText android:id="@+id/text_2"
        android:hint="@string/hint_2"
        android:inputType="textMultiLine"
        android:maxLines="2"
        android:gravity="top"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_alignParentBottom="true"
        android:visibility="gone" />    
    <EditText android:id="@+id/text_1"
        android:hint="@string/hint_1"
        android:inputType="textMultiLine"
        android:gravity="top"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_below="@id/spinner"
        android:layout_above="@id/text_2"
        android:layout_alignWithParentIfMissing="true" />
</RelativeLayout>

附:这件事只发生在我的野火上,在模拟器上很少见。朋友的Desire HD完全没有问题。我不知道这是否有什么不同...

提前感谢您的帮助。

安东尼

【问题讨论】:

    标签: android android-layout android-xml


    【解决方案1】:

    我也有同样的问题。我已经测试过,这只发生在多行模式下的 EditText 以及当 SoftInputMode 设置为 adjustPan 时。这很可能是一个 Android 错误。

    我找到的唯一解决方案是删除 adjustPan。

    【讨论】:

      猜你喜欢
      • 2021-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多