【问题标题】:space between editText and softkeyboardeditText 和软键盘之间的空间
【发布时间】:2015-04-13 15:35:50
【问题描述】:

我有一个几乎在底部有一个 editText 字段的活动。 当我专注于那个editText字段时,键盘会出现并将我的edittext字段向上推。

当它停止时,editText 和我的软键盘之间没有空间。

是否可以添加一些边距?

这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/bg_yellow"
android:orientation="vertical"
>

<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_gravity="bottom"
    android:layout_alignParentBottom="true"
    android:paddingTop="25dp"
    >

    <RelativeLayout 
        android:layout_width="340dp"
        android:layout_height="100dp"
        android:layout_centerHorizontal="true"
        >

        <EditText 
            android:layout_width="340dp"
            android:layout_height="45dp"
            android:background="@drawable/edit_text_field"
            android:inputType="text"
             />

    </RelativeLayout>
</RelativeLayout>

键盘出现前editText字段的位置: http://postimg.org/image/826fwy18z/

和显示键盘时的图像,光标和键盘之间没有空格: http://postimg.org/image/97qlfb4zx/

【问题讨论】:

  • Jan,你能上传截图吗?我不明白这个问题。
  • 我已经尝试过,但没有足够的声望点:(还有其他方法吗?
  • 已经上传图片了:)
  • 你找到答案了吗?我有同样的问题

标签: android xml


【解决方案1】:

您可以在清单文件中使用 Activity 的android:windowSoftInputMode 属性。

在您的情况下使用 android:windowSoftInputMode="adjustResize"。您也可以查看其他属性。

希望这会有所帮助。

谢谢。

【讨论】:

    【解决方案2】:

    在编辑文本字段的底部添加边距

    android:layout_marginBottom="10dp"
    

    【讨论】:

    • 我之前试过,但是对空间没有任何影响。