android - 按钮在 Android 中显示键盘时更改其位置

标签 android android-layout android-emulator

我正在尝试做以下设计

Valid XHTML

我的 XML 代码如下

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="fill_vertical" >

    <EditText
        android:id="@+id/patientid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="50dp"
        android:layout_toLeftOf="@+id/speak"
        android:ems="10"
        android:hint="@string/patientidhint" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/speak"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/patientid"
        android:layout_alignParentRight="true"
        android:layout_marginRight="10dp"
        android:onClick="speak"
        android:text="@string/speak" 
        tools:context=".CreatingPatientFolder"
        />
    
     <ListView
        android:id="@+id/lvTextMatches"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/speak" 
        android:layout_above="@+id/btn_Submit"/>

    <Button
        android:id="@+id/btn_Submit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="50dp"
        android:layout_alignParentBottom="true"
        android:gravity="center"
        android:paddingBottom="10dp"
        android:paddingLeft="30dp"
        android:paddingRight="30dp"
        android:paddingTop="10dp"
        android:text="Submit"
        android:textSize="20sp"
        tools:ignore="HardcodedText" />

</RelativeLayout>

现在当我运行这个项目时,它会显示如下

Valid XHTML

那么谁能告诉我为什么我的按钮向上移动,也请帮我解决这个问题。

最佳答案

我认为按钮被移动的原因是因为你的列表是空的,你有足够的空间来移动按钮并且按钮不在编辑文本下方,因此它可以重叠它。

您的 list 中有一个名为“windowSoftInputMode”的属性。此属性指定软键盘的行为方式。

你可以使用:

android:windowSoftInputMode="stateVisible|adjustNothing

关于android - 按钮在 Android 中显示键盘时更改其位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17167044/

相关文章:

Android list 使用权限与 Android 设备规范

android - 如何发送高优先级 GCM?

javascript - 使用 Titanium 添加 native 日历

android - 如何在 android 上获得默认警报对话框有一个黑色主题

android - 如何在运行时自定义以 XML 定义的自定义可绘制对象?

android - 如果在 onCreate() 中设置,为什么 ViewTreeObserver > OnScrollChangedListener 在 Android 2.x 上不被调用?

android - Android 模拟器无法访问 Soap Web 服务?

java - 我想要两个 ListView 同时滚动

windows - 如何使用 VirtualBox 和 Ubuntu 作为开发环境以及 Windows 10 和 Android Studio 作为 Android 模拟器在 React Native 中进行开发

android - 如何根据屏幕尺寸将不同的数据传递给 Web 服务