I have an Activity
which is displayed fullscreen. This works perfectly with many layouts I have tried, except for when the CoordinatorLayout
is the roo
I had a similar issue and had to hack a bit of a solution. Instead of an ImageView, my CoordinatorLayout child view is for streaming a video. Since I am streaming a video during rotation, I need to to watch for configChanges and override onConfigurationChanged. This may not work for you if you do not want to override onConfigurationChanged, but it may work out. Like I said, it's a bit of a hack, but works for me.
I end up fully expanding the Toolbar, storing the offset, then hiding it (treating it as a standard view). Then when I rotate back, I am resizing it to whatever the offset was when the user rotated the device.
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
showToolbar();
mViewPager.setVisibility(View.VISIBLE);
} else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
hideToolbar();
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
mViewPager.setVisibility(View.GONE);
}
}
public void hideToolbar()
{
setCurrentOffset();
expandToolbarToHeight(0);
findViewById(R.id.toolbar).setVisibility(View.GONE);
}
public void showToolbar()
{
expandToolbarToHeight(oldOffset);
findViewById(R.id.toolbar).setVisibility(View.VISIBLE);
}
public void setCurrentOffset() {
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams();
AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();
if (behavior != null) {
oldOffset = behavior.getTopAndBottomOffset();
}
}
public void expandToolbarToHeight(int height) {
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams();
AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();
if (behavior != null) {
behavior.setTopAndBottomOffset(height);
behavior.onNestedPreScroll(mCoordinatorLayout, mAppBarLayout, null, 0, 1, new int[2]);
}
}