Search code examples
androidandroid-layoutandroid-scrollview

Android ScrollView, under Action Bar on Softkeyboard


I've read several discussions around this issue and it has to do with the android:windowSoftInputMode="stateHidden|adjustResize" (as well as adjustPan) of the manifest file when attempting to get a ScrollView of a LinearLayout to adjust when the keyboard is shown.

I have a layout that has a LinearLayout inside of a ScrollView that contains 10 LinearLayout sections (TextView/EditText views). I have tried every combination I have read about and no matter what, when the keyboard is opened as a result of clicking on the top EditText, the view is adjusted (panned) such that the top field is behind the action bar. I can scroll to the bottom of the page, but I can't get to the top EditText - I can only scroll to the 2nd one. I can try and pull down and I can start to see the top EditText but can't get it to show unless I dismiss the keyboard (which obviously I can't edit the text then).

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.example.myproject.FirstActivity"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/scrollView"
    tools:showIn="@layout/activity_work"
    android:layout_gravity="center_horizontal">

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="x1"
            android:layout_weight="50"/>

        <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:inputType="numberDecimal"
            android:ems="10"
            android:id="@+id/work_one"
            android:hint="0"
            android:gravity="right"
            android:selectAllOnFocus="true"
            android:textAlignment="gravity"
            android:layout_weight="50" />
    </LinearLayout>
    .
    . (9 more of these)
    .
  </LinearLayout>
</ScrollView>

UPDATE:

so I tried: android:windowSoftInputMode="adjustResize" and / or android:windowSoftInputMode="adjustPan" and the soft keyboard shifts the top fields under the action bar.

Thoughts?


Solution

  • Try either android:windowSoftInputMode="adjustResize" or android:windowSoftInputMode="adjustPan"

    From the doc

    "adjustResize"

    The activity's main window is always resized to make room for the soft keyboard on screen.

    "adjustPan"

    The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.

    I copied the answer from this Stack Overflow answer