Search code examples
androidandroid-edittextandroid-softkeyboardandroid-screen

Screen keeps moving while typing when EditText is in focus


My EditText is positioned below an ImageView. When I start typing on the EditText, the screen won't stay put and keeps scrolling up and down as shown in this video. Another problem is the keyboard covers part of the EditText.

This is what my activity's XML looks like:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:orientation="vertical"
    >

    <ImageView
        android:id="@+id/display_photo"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:adjustViewBounds="true"/>

    <android.support.design.widget.TextInputLayout
        android:id="@+id/caption_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="7dp"
        android:theme="@style/LoginFieldLayout"
        app:hintTextAppearance="@style/MomentLabel">

        <android.support.design.widget.TextInputEditText
            android:id="@+id/et_start_photo_story_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="5dp"
            android:adjustViewBounds="true"
            android:gravity="bottom"
            android:hint="@string/caption_hint"
            android:inputType="textNoSuggestions|textMultiLine"
            android:lines="8"
            android:maxLength="500"
            android:minLines="1"
            android:paddingBottom="15dp"
            android:privateImeOptions="nm"
            android:textColor="@color/black"
            android:textColorHint="@color/black"
            android:textSize="18sp"
            android:theme="@style/StartAdventureEditText" />

    </android.support.design.widget.TextInputLayout>

I've also added this line in the manifest file: android:windowSoftInputMode="adjustResize".


Solution

  • Use "adjustNothing" as below in your androidManifestFile.xml

        <activity
            android:name="com.myApp.ui.activity.MainActivity"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateAlwaysHidden|adjustNothing" />
        <activity