Button Changes it position when Keyboard gets displayed in Android

喜夏-厌秋 提交于 2019-12-24 15:16:48

问题


I am trying to do following Design

My XML Code is as follow

<?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>

Now when I run this project it gets displayed as follow

So can any one please tell me why my button is getting shift upwards also please help me to remove this issue.


回答1:


I think the reason why the button is moved is because your list is empty, you have enough room to move the button and the button is not bellow the edit text, therefore it can overlap it.

There is a property in your manifest called "windowSoftInputMode". This property specifies how the soft keyboard should behave.

You could use:

android:windowSoftInputMode="stateVisible|adjustNothing



回答2:


add this in ur Button:

android:layout_marginTop="20dp"

i did not test . May be Solve your problem.




回答3:


One More thing that helped me was the change of theme in the Manifest file to NoActionBar and FullScreen (In case you don't want to use the ActionBar like me).

android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen"


来源:https://stackoverflow.com/questions/17167044/button-changes-it-position-when-keyboard-gets-displayed-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!