I\'m pretty sure this is a bug, so I\'m asking for a workaround. My layout is like:
The trick is to add android:layout_gravity="fill_vertical"
to the NestedScrollView
. This way the toolbar collapses and expands smoothly & reacts to scroll gestures for any non-empty NestedScrollView
, no matter its size.
Of course if the scroll view is empty, the toolbar won't collapse by scrolling in the "content" part of the screen. But that doesn't seem so bad to me.
Looks like this solution has some issues with larger contents, as the very bottom part of the content will remain hidden. I could find that the hidden part is (appears to be) as big as the collapsed toolbar height. That makes it easy to define a workaround - just add a margin to the bottom of the ScrollView, so that it gets measured and releases the bottom, hidden part. Thus:
android:layout_gravity="fill_vertical"
android:layout_marginBottom="?attr/actionBarSize"
or whatever size you gave to the Toolbar
in your view. Note that this solution fits well with small and large contents, but scrolling is not so smooth with smaller ones.
From early tests, it looks that this bug has been fixed in the v22.2.1 release of the Support Design Library.