开发者

Android's EditText is hidden when the virtual keyboard is shown and a SurfaceView is involved

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/开发者_StackOverflow中文版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)


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.


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


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"


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 liananse@163.com

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜