Ivan Fork
Ivan Fork

Reputation: 822

Scroll to the bottom with opened keyboard and adjustPan

Is it possible to scroll to a button that aligned to the bottom of the layout when keyboard is overlaying the button when windowSoftInputMode="adjustPan"?

I don't want to use windowSoftInputMode="adjustResize" because I want the button to be under the keyboard, and I want to scroll to the button when keyboard is opened.

Example layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true">

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

        <EditText
            android:layout_width="match_parent"
            android:layout_height="70dp"
            android:hint="edit text" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="70dp"
            android:hint="edit text" />

    </LinearLayout>

</ScrollView>

<Button
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:layout_alignParentBottom="true"
    android:text="button" />

</RelativeLayout>

I need to scroll to the button that is under the keyboard:

img

Upvotes: 2

Views: 921

Answers (1)

Try this add android.support.v4.widget.NestedScrollView instead of Relativelayout and make android:transcriptMode="alwaysScroll" always Scroll

<android.support.v4.widget.NestedScrollView     
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:transcriptMode="alwaysScroll">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <EditText
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:hint="edit text" />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:hint="edit text" />
    <Button
          android:layout_width="match_parent"
          android:layout_height="40dp"
          android:layout_alignParentBottom="true"
          android:text="button" />
      </LinearLayout>
    </ScrollView>
 </android.support.v4.widget.NestedScrollView>

Upvotes: 0

Related Questions