Skip to content

Instantly share code, notes, and snippets.

@avianey
Created October 11, 2014 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avianey/497f9c69d198ea7dd59b to your computer and use it in GitHub Desktop.
Save avianey/497f9c69d198ea7dd59b to your computer and use it in GitHub Desktop.
Libgdx square AndroidFragmentApplication that fills as much of the screen as possible
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
config.useAccelerometer = false;
config.useCompass = false;
config.useWakelock = true;
config.numSamples = 1;
config.resolutionStrategy = new ResolutionStrategy() {
@Override
public MeasuredDimension calcMeasures(int widthMeasureSpec, int heightMeasureSpec) {
int width = widthMeasureSpec;
int height = heightMeasureSpec;
if ((View.MeasureSpec.AT_MOST & widthMeasureSpec) != 0) {
width -= View.MeasureSpec.AT_MOST;
} else if ((View.MeasureSpec.EXACTLY & widthMeasureSpec) != 0) {
width -= View.MeasureSpec.EXACTLY;
}
if ((View.MeasureSpec.AT_MOST & heightMeasureSpec) != 0) {
height -= View.MeasureSpec.AT_MOST;
} else if ((View.MeasureSpec.EXACTLY & heightMeasureSpec) != 0) {
height -= View.MeasureSpec.EXACTLY;
}
final int d = Math.min(width, height);
return new MeasuredDimension(d, d);
}
};
return initializeForView(new ReversiGame(), config);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment