Button Changes it position when Keyboard gets disp

2019-07-22 12:02发布

问题:

I am trying to do following Design

Valid XHTML http://i39.tinypic.com/2rfcxo1.png

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

Valid XHTML http://i40.tinypic.com/9u5b1y.png

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"