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).
If you use different Fragments inside your CoordinatorLayout you will face the problem, that some Fragments have scrollable content and some should not scroll. Your Toolbar has the scrolling flags "scroll|enterAlways", which is ok for the former layouts, but not ok for the latter. My solution is a custom AppBarLayout.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:
public class MyScrollBehavior extends AppBarLayout.Behavior {
private View content;
public MyScrollBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onMeasureChild(CoordinatorLayout parent, AppBarLayout appBarLayout, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed) {
if(content == null) {
content = parent.findViewById(R.id.container);
}
if(content != null) {
boolean shouldNotScroll = content.findViewWithTag(parent.getContext().getString(R.string.contentShouldNotScrollTag)) != null;
Toolbar toolbar = (Toolbar) appBarLayout.findViewById(R.id.toolbar);
AppBarLayout.LayoutParams params =
(AppBarLayout.LayoutParams) toolbar.getLayoutParams();
if (shouldNotScroll) {
params.setScrollFlags(0);
appBarLayout.setExpanded(true, true);
} else {
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
| AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
}
}
return super.onMeasureChild(parent, appBarLayout, parentWidthMeasureSpec, widthUsed, parentHeightMeasureSpec, heightUsed);
}
}