安卓:EditText被键盘遮挡而无法显示

11
在撰写这个问题之前,我已经阅读了以下答案/文章:
  1. Android软键盘覆盖EditText字段
  2. Android键盘遮挡EditText
  3. http://developer.android.com/resources/articles/on-screen-inputs.html
  4. 软键盘与EditText字段重叠
Android软键盘默认设置为pan,这意味着它将保持所有可编辑区域在键盘上方。但是它并没有pan到足够的高度。当我运行它并按下靠近屏幕底部的edittext时,键盘出现并移动edittext,但未移动到能够看到正在输入的内容的足够高度。我尝试使用了以下方法:
  1. 在Activity的清单文件中使用 android:windowSoftInputMode="adjustPan"。这没有任何作用。我也尝试使用 adjustUnspecifiedadjustResize 的值,但都不起作用。

  2. 在清单文件中使用 <uses-sdk android:minSdkVersion="3" />。我的应用程序针对2.1及以上的SDK。尽管如此,我也尝试过它,但没有效果。

  3. 使用ScrollView。这也不起作用。

是否有一种方法可以手动管理键盘按下特定edittext时进行的“panning”量。以下是我的xml文件。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:background="#ffffff">       

    <ImageView 
    android:id="@+id/header"
    android:layout_width="320dip"
    android:layout_height="86dip"
    android:background="@drawable/header_bg">
    </ImageView>

    <ImageView 
    android:layout_width="320dip"
    android:layout_height="200dip"
    android:layout_alignParentBottom="true"
    android:background="@drawable/bg1_btm">
    </ImageView>

        <TextView android:text="Hostname" 
        android:id="@+id/lbl_hostname"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/header"/>

        <TextView android:text="(Current)" 
        android:id="@+id/lbl_hostname_current"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/lbl_hostname"
        android:layout_below="@id/header" />

        <EditText android:text="EditText" 
        android:id="@+id/editText_hostname" 
        android:layout_below="@id/lbl_hostname"  
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:maxLength="25">
        </EditText>

        <TextView android:text="Registration URL" 
        android:id="@+id/lbl_registration"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_below="@id/editText_hostname" />

        <TextView android:text="(Current)" 
        android:id="@+id/lbl_registration_current"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_below="@id/editText_hostname"
        android:layout_toRightOf="@id/lbl_registration" />

        <TextView android:text="http://" 
        android:id="@+id/lbl_url_prefiz"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_below="@id/lbl_registration"
        android:paddingTop="10dip" />

        <EditText android:text="EditText" 
        android:id="@+id/editText_registration" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_toRightOf ="@id/lbl_url_prefiz"
        android:layout_below="@id/lbl_registration">
        </EditText>

        <TextView android:text="Chat" 
        android:id="@+id/lbl_chat"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/editText_registration"/>

        <TextView android:text="(Current)" 
        android:id="@+id/lbl_chat_current"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/editText_registration"
        android:layout_toRightOf="@id/lbl_chat"/>

        <EditText android:text="EditText" 
        android:id="@+id/editText_chat" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/lbl_chat">
        </EditText>

        <TextView android:text="SSID" 
        android:id="@+id/lbl_ssid"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_below="@id/editText_chat" />

        <TextView android:text="(Current)" 
        android:id="@+id/lbl_ssid_current"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_below="@id/editText_chat"
        android:layout_toRightOf="@id/lbl_ssid"
        />

        <EditText android:text="EditText" 
        android:id="@+id/editText_ssid" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/lbl_ssid"
        android:maxLines="1"
        android:inputType="text"
        android:layout_marginBottom="25dip">
        </EditText> 

        <Button android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:id="@+id/ButtonSave" 
        android:text="Save" 
        android:layout_below="@id/editText_ssid"
        android:layout_alignParentLeft="true">
        </Button>

        <Button android:text="Continue" 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:id="@+id/ButtonContinue" 
        android:layout_below="@id/editText_ssid" 
        android:layout_alignParentRight="true">
        </Button>

</RelativeLayout>

答案在这篇文章里:https://dev59.com/EFPTa4cB1Zd3GeqPfQAC - kctang
谢谢。我现在已经想出一种解决方法,但稍后还会检查一下。 - skaneria
不是我知道的。我所做的只是在我的应用程序中将按钮向上移动了一点。 - skaneria
2个回答

8

请尝试

android:windowSoftInputMode="adjustResize"  

对我来说运作良好 :)


6

尽量使用fill_parent或match_parent来设置所有控件的布局高度和宽度,而不是使用硬编码数值...

如果你正在使用此代码,请删除它,因为它可能会将你的应用程序向下推...

getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

希望它能够正常工作...


谢谢。我已经没有这个项目来尝试了。但是,如果它对其他人有用,我会接受它作为答案。感谢您的帮助。 - skaneria
使其可见,但禁用滚动视图和上方的视图存在一些问题... - deadfish

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接