I have a problem with my FrameLayout (Container in Drawer Layout). The height of the FrameLayout exceeds the screen height (below the android default menu buttons at bottom).
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/navContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
My first attempt was to set a
android:layout_marginBottom="?attr/actionBarSize"
at the FrameLayout. This solved the solution for non-scrollable views having a "fixed" height in terms of no vertically scrollable content (like a usual RelativeLayout withmatch_parent
height). Aligning a component to the parent bottom (android:layout_alignParentBottom="true"
) results in a still visible element. In Android Studio's Previewer the no exceeding of the height is visible.However, this marginBotton-fix introduces a new problem for fragments whose root view is scrollable (like a RecyclerView). For these views when scrolling down the bottom margin will become visible in a white bar (in case white is the background color). This seams reasonable, as for those views the nested scrolling feature will slide out the toolbar
tl;dr I worked around that issue by applying the the
?attr/actionBarSize
as bottom margin to non-scrollable fragments that are shown inside the Framelayout. Prior to that I set the height of the toolbar to be?attr/actionBarSize
.Activity layout:
Fragment layout:
The only downside I faced right now is the white space to be shown in Android Studio's Previewer while creating the fragment layout.
If you use different
Fragments
inside yourCoordinatorLayout
you will face the problem, that someFragments
have scrollable content and some should not scroll. YourToolbar
has the scrolling flags "scroll|enterAlways
", which is ok for the former layouts, but not ok for the latter. My solution is a customAppBarLayout.Behavior
which switches the scrolling flags dependant on the custom tag (contentShouldNotScrollTag). Set this tag for the layouts, which should not scroll like this:As the result, the height of this Fragment will not exceed the screen's height. Here is the custom behavior class for the
AppBarLayout
: