Skip to content

Instantly share code, notes, and snippets.

@jgilfelt
Last active December 10, 2015 02:18
Show Gist options
  • Save jgilfelt/4366555 to your computer and use it in GitHub Desktop.
Save jgilfelt/4366555 to your computer and use it in GitHub Desktop.
Custom LinearLayout needed for fullscreen YouTube player when using SYSTEM_UI_FLAG_HIDE_NAVIGATION
package com.readystatesoftware.views;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.LinearLayout;
public class FittingLinearLayout extends LinearLayout {
public FittingLinearLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public FittingLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FittingLinearLayout(Context context) {
super(context);
}
@Override
protected boolean fitSystemWindows(Rect insets) {
LinearLayout.LayoutParams params = ((LinearLayout.LayoutParams)this.getLayoutParams());
int top = params.topMargin;
// lets apply any left, right or bottom margin supplied by the framework insets
// so the YouTubePlayerFragment controls aren't obscured when we reveal the
// system UI in SYSTEM_UI_FLAG_HIDE_NAVIGATION mode
params.setMargins(insets.left, top, insets.right, insets.bottom);
return super.fitSystemWindows(insets);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment