This is an Android bug in my opinion, we just fix this issue doing this:
<FrameLayout android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout android:id="@+id/layout_to_hide"
android:layout_width="match_parent"
android:layout_height="wrap_content">
//Put here your views
</LinearLayout>
</FrameLayout>
Just hide LinearLayout with id LAYOUT_TO_HIDE with Visible.GONE
and then root FrameLayout will collapse its height giving you a “hidden” with non-blank-space header.