2013-01-18 55 views
0

可能重复:
background layout moving when soft keyboard displayed - android如何修复EditText?

我有一个包含severals意见和EditText上一个布局文件:

<RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"> 
    <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/connect" 
      android:id="@+id/btnConnect" android:layout_alignParentRight="true" android:layout_alignParentTop="true"/> 
    <Spinner 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/spServers" 
      android:layout_toLeftOf="@+id/btnConnect" android:layout_alignTop="@+id/btnConnect" 
      android:layout_alignBottom="@+id/btnConnect" android:layout_alignParentLeft="true"/> 
    <ToggleButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/btnType" android:layout_alignLeft="@+id/btnConnect" 
      android:layout_below="@+id/btnConnect" android:layout_alignRight="@+id/btnConnect" android:textOff="@string/text" 
      android:textOn="@string/grid" /> 
    <Spinner 
      android:layout_width="98dp" 
      android:layout_height="22dp" 
      android:id="@+id/spDataBases" android:layout_toLeftOf="@+id/btnConnect" 
      android:layout_below="@+id/btnConnect" 
      android:layout_alignBottom="@+id/btnType" android:layout_alignLeft="@+id/spServers"/> 
    <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/check" 
      android:id="@+id/btnCheck" android:layout_alignLeft="@+id/spServers" android:layout_alignParentBottom="true"/> 
    <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/run" 
      android:id="@+id/btnRun" android:layout_toRightOf="@+id/btnCheck" android:layout_alignTop="@+id/btnCheck" 
      android:layout_toLeftOf="@+id/btnLoad"/> 
    <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/load" 
      android:id="@+id/btnLoad" android:layout_alignRight="@+id/btnConnect" 
      android:layout_alignTop="@+id/btnCheck"/> 
    <EditText 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/txtSQL" android:layout_alignLeft="@+id/spServers" android:layout_below="@+id/btnType" 
      android:layout_alignRight="@+id/btnConnect" android:layout_above="@+id/btnCheck" 
      android:gravity="left|top" android:singleLine="false" android:textAlignment="gravity"/> 
</RelativeLayout> 

它看起来像这样:

enter image description here

但是,当我想输入的东西,我得到这个问题:

I'm trying to type something

请帮我解决这个问题。当我输入一些文字时,我不想改变布局上的屏幕位置。当用户尝试输入内容时,它正在向上移动。

+0

什么问题? –

+0

它应该做什么? – MrZander

+0

@MrZander我想修复它。当我输入一些文字时,我不想改变布局上的屏幕位置。 – ruslanys

回答

0

您可以尝试告诉Android在键盘弹出时不调整您的布局大小,确保您输入的内容可见。 (文档:http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

以下内容添加到您应用的清单:(在相关的活动,而不是下面的虚拟之一)

<activity android:name="Activity" 
    .. 
    android:windowSoftInputMode="adjustPan" 
    .. 
</activity> 

,如果当你点击你的问题正在发生的事情是我不清楚EditText和键盘出现了,还是只有一次开始输入才会出现?如果后者是这样的话,我的答案可能无济于事。我也不确定“adjustPan”是否可取,但值得一试!把你的整个RelativeLayout放在一个ScrollView中也是一个好主意。