Search code examples
androidcoordinator-layoutnestedscrollview

CoordinatorLayout with NestedScrollView doesn't resize with adjustResize


I have a view which contains a CoordinatorLayout which wraps an AppBarLayout and a NestedScrollView. Inside the NestedScrollView there is an EditText

I'm having problems showing the soft input keyboard and having it correctly resize the view.

With the usual flag android:windowSoftInputMode="adjustResize" everything seems to work fine, apart from when you hide the input.

With the input open (image 2), the NestedScrollView (with the boring grey background) has shrunk so you can scroll to the previously "covered" portion. All good. However, once the input is hidden (image 3), the NestedScrollView has not grown to refill the space and you can see it's parent CoordinatorLayout (which I've coloured in the fetching red).

enter image description here enter image description here enter image description here

I've tried this answer https://stackoverflow.com/a/31286789/726954, adding a myserious android:layout_gravity="fill_vertical" tag, but all this does is limit the NestedScrollView height which ends up cutting off child elements (although it does fix the problem with it refusing to refill it's container).

Am I missing something or is this a bug with the CoordinatorLayout

Here is a mockup of my XML:

<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/red_granate">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/actionBarContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">

        <View
            android:id="@+id/statusBarPadding"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:background="@color/primary_material_dark"/>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?android:attr/actionBarSize"
            android:background="@color/primary_material_dark"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:layout_scrollFlags="scroll|enterAlways"/>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:background="@color/grey"
        android:id="@+id/nestedScrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

            <EditText
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="1900dp"/>
        </FrameLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

Solution

  • Are you using the latest version - 22.2.1? I had similar problems with 22.2.0.

    compile 'com.android.support:design:22.2.1'
    compile 'com.android.support:recyclerview-v7:22.2.1'