【问题标题】:Android's EditText is hidden when the virtual keyboard is shown and a SurfaceView is involved当显示虚拟键盘并涉及 SurfaceView 时,Android EditText 被隐藏
【发布时间】:2010-06-04 22:51:38
【问题描述】:

我有一个简单的用户界面:EditText 应该位于 SurfaceView 下方。 我使用RelativeLayout 来排列这两个视图。

现在,当我点击 EditText 打开虚拟键盘时,SurfaceView 会向上滑动,但 EditText 被隐藏并且不显示键入的字符串。

要重现,请使用以下布局 XML 代码:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/RelativeLayout01"
android:layout_height="fill_parent" 
android:layout_width="fill_parent">

<SurfaceView
android:id="@+id/SurfaceView01"
android:layout_width="fill_parent" 
android:layout_height="wrap_content">
</SurfaceView>

<EditText 
android:id="@+id/EditText01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentLeft="true" 
android:layout_alignParentBottom="true" 
android:selectAllOnFocus="true"
android:textStyle="normal"
android:singleLine="true">
</EditText> 

</RelativeLayout>

主Activity类只需要显示布局即可。当我启动程序并点击 EditText 时,会出现虚拟键盘,但 EditText 字段消失了。

可能是 RelativeLayout 导致了问题,但我不知道如何使用另一个 Layout 类重现相同的布局。

欢迎任何建议,非常感谢您的帮助。

谢谢。

编辑:

这里有两张截图,一张在底部显示没有虚拟键盘的 EditText,一张有虚拟键盘但没有 EditText。有趣的是,SurfaceView 和 EditText 实际上向上移动,EditText 只是消失了。顺便说一句,如果按钮位于 EditText 旁边,这也会发生在按钮上。

EditText below a SurfaceView (left); EditText is gone (right)

【问题讨论】:

  • 您可以考虑附上两张截图,一张是隐藏软键盘(即“正常”),另一张是在您点击EditText 调出键盘后。您可以使用 DDMS 来制作屏幕截图。

标签: android surfaceview


【解决方案1】:

正如thread about this bug 中的评论者所建议的那样,通过将SurfaceViewGLSurfaceView 的背景颜色也设置为透明mSurfaceView.setBackgroundColor(Color.TRANSPARENT); 来解决此问题非常容易。

我在三星 Galaxy Tab 10.1 上的 Honeycomb (v13) 上按 EditText 时出现此问题。问题是在调整GLSurfaceView 的大小后,它的位置仍然是一个覆盖EditText 的黑色矩形。此解决方案通过使错误的矩形透明来起作用,因此可以看到 EditText

【讨论】:

  • 非常感谢,希望能+100!
【解决方案2】:

在您的 AndroidManifest.xml 中为您的活动添加以下代码 android:windowSoftInputMode="adjustPan"

【讨论】:

    【解决方案3】:

    是的,没错! 在您的 AndroidManifest.xml 中为您的活动添加以下代码 android:windowSoftInputMode="adjustPan"

    在您的编辑文本中,只需添加:

    android:imeOptions="flagNoFullscreen"
    

    【讨论】:

      【解决方案4】:

      我发现它在不同的设备上有不同的结果,然后我使用ScrollView作为根视图并将布局放入ScrollView,当使用fullScreen模式时它可以正常工作。如果您仍然有问题,请务必设置 android:fillViewport="true" 让我知道 liananse@163.com

      【讨论】:

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