当显示虚拟键盘并且涉及 SurfaceView 时,Android 的 EditText 会被隐藏

发布于 2024-09-03 22:09:54 字数 1372 浏览 2 评论 0原文

我有一个简单的用户界面: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 旁边,也会发生这种情况。

SurfaceView 下方的 EditText(左); EditText 消失了(右)

I have a simple user interface: an EditText should be located below a SurfaceView.
I use a RelativeLayout to arrange these two views.

Now, when I tap on the EditText to open the virtual keyboard the SurfaceView slides up but the EditText is hidden and does not show the typed string.

To reproduce, use the following layout XML code:

<?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>

The main Activity class only needs to show the layout. When I start the program and tap the EditText, the virtual keyboard appears but the EditText field is gone.

Maybe the RelativeLayout is causing the problems, but I don't know how to reproduce the same layout with another Layout class.

Any suggestions are welcome, I really appreciate your help.

Thanks.

Edit:

Here are two screenshots, one showing the EditText at the bottom without virtual keyboard, one with virtual keyboard but with no EditText. It is interesting to note that the SurfaceView and the EditText actually shift upward, the EditText just disappears. BTW this also happens to a button if it is next to the EditText.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

盛夏尉蓝 2024-09-10 22:09:54

正如有关此错误的帖子中的评论者所建议的,修复此问题非常容易通过使用 mSurfaceView.setBackgroundColor(Color.TRANSPARENT);SurfaceViewGLSurfaceView 的背景颜色设置为透明来解决此问题。

当我在 Samsung Galaxy Tab 10.1 上的 Honeycomb (v13) 上按 EditText 时,出现了此问题。问题是,在调整 GLSurfaceView 大小后,其位置仍然是一个黑色矩形,覆盖了 EditText。该解决方案的工作原理是使错误的矩形透明,以便可以看到 EditText

As a commenter in the thread about this bug suggested, it is very easy to fix this problem by setting the background color of the SurfaceView or GLSurfaceView to transparent with mSurfaceView.setBackgroundColor(Color.TRANSPARENT); as well.

This problem occurred for me when pressing an EditText on Honeycomb (v13) on a Samsung Galaxy Tab 10.1. The issue was that after the GLSurfaceView was resized, in its place was still a black rectangle which was covering the EditText. This solution works by making that erroneous rectangle transparent, so the EditText can be seen.

遗心遗梦遗幸福 2024-09-10 22:09:54

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

Add the follow code for your activity in your AndroidManifest.xml
android:windowSoftInputMode="adjustPan"

心头的小情儿 2024-09-10 22:09:54

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

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

android:imeOptions="flagNoFullscreen"

Yes, it's right!
Add the follow code for your activity in your AndroidManifest.xml android:windowSoftInputMode="adjustPan"

And in your edit text, just add:

android:imeOptions="flagNoFullscreen"
樱花落人离去 2024-09-10 22:09:54

我发现它在不同的设备上有不同的结果,然后我使用ScrollView作为根视图并将布局放入ScrollView中,当使用全屏模式时它工作正常。如果您仍然遇到问题,请务必设置 android:fillViewport="true" 让我知道 [电子邮件受保护]

i found that it has different result on different devices,then i use ScrollView as the root view and put the layout into ScrollView, when use fullScreen mode it works fine. and be sure to set android:fillViewport="true" if you still have some problem let me know [email protected]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文