Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 578
Cactus Avatar asked May 16 '18 12:05

Cactus


1 Answers

<?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"
   android:fitsSystemWindows="true"
   tools:context=".MainActivity">

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

    <ImageView
        android:id="@+id/image"
        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:layout_below="@+id/image"
        android:isScrollContainer="true">

        <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>

</RelativeLayout>

TRY THIS CODE IN THIS CODE I HAVE REPLACED FRAME LAYOUT WITH RELATIVE LAYOUT AND SET NESTED SCROLL VIEW BELOW THE IMAGE

like image 108
Jay Thummar Avatar answered Oct 22 '22 05:10

Jay Thummar