Sunday, 27 May 2018

Interaction of adjustPan and a NestedScrollView

In my layout, I have an EditText in a NestedScrollView. When the EditText is edited with a soft keyboard, I would like the NestedScrollView's content to be scrolled up. However, instead, the whole contents of the activity is scrolled away, including an ImageView that shouldn't be moved:

Before After

What I would like (bad Gimp-job):

enter image description here

The below is a simplified version of my layout that still exhibits the problem:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="150dp"
            app:srcCompat="@mipmap/ic_launcher" />

        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true"
            android:isScrollContainer="true"
            android:paddingTop="150dp">

            <LinearLayout
                android:id="@+id/layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/textView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Aaa aaaaaaaaaa aaa aaaaaaaa aaaa. Aaa aaaaaaa aaa aa aaa aaaaaa aaaaa. Aaaaaaaa aaaaaaaaaaa aa aaaaaaaa aaaa:Aaa aaaaaaaaaa aaa aaaaaaaa aaaa. Aaa aaaaaaa aaa aa aaa aaaaaa aaaaa. Aaaaaaaa aaaaaaaaaaa aa aaaaaaaa aaaa: Aaa aaaaaaaaaa aaa aaaaaaaa aaaa. Aaa aaaaaaa aaa aa aaa aaaaaa aaaaa. Aaaaaaaa aaaaaaaaaaa aa aaaaaaaa aaaa:  Aaa aaaaaaaaaa aaa aaaaaaaa aaaa. Aaa aaaaaaa aaa aa aaa aaaaaa aaaaa. Aaaaaaaa aaaaaaaaaaa aa aaaaaaaa aaaa:  aaa aaaaaa aaaaa. Aaaaaaaa aaaaaaaaaaa aa aaaaaaaa aaaa aa:  aaa aaaaaa aaaaa. Aaaaaaaa aaaaaaaaaaa aa aaaaaaaa  aa:  aaa aaaaaa aaaaa. Aaaaaaaa aaaaaaaaaaa aa aaaaaaaa " />

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:inputType="text" />

            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>

    </FrameLayout>
</android.support.design.widget.CoordinatorLayout>

I've tried various combinations of windowSoftInputMode on the activity and isScrollContainer on the NestedScrollView, but no combination gives me what I would like: when the soft keyboard is popped up, I would like the text to be scrolled up, without changing the NestedScrollView's visible margin or the ImageView behind it.



from Interaction of adjustPan and a NestedScrollView

No comments:

Post a Comment