CoordinatorLayout with NestedScrollView doesn't resize with adjustResize
Asked Answered
B

1

3

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://mcmap.net/q/1328760/-collapsingtoolbarlayout-doesn-39-t-work-well-with-nestedscrollview, 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>
Biggers answered 18/8, 2015 at 13:40 Comment(0)
H
4

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'
Harbaugh answered 18/8, 2015 at 15:6 Comment(2)
Take it that 22.2.0 was broken?Biggers
22.2.0 had many problems and in a bit complicated cases it showed it. For example in RecyclerView scrollBy, there is a NPE that sometimes happens and there are problems with row animation, that are still in 22.2.1Harbaugh

© 2022 - 2024 — McMap. All rights reserved.