I have found other solution for this and test it my self.
Dealing with all the device resolutions scattered around the globe. The existing resolution policies offer either a stretch-to-fit scale, black bars or leave it to you to do the scaling.
The class I have here is another option that scales your screen up to fill the screen, whilst retaining the 1:1 assets ratio of your graphics.
public class CroppedResolutionPolicy extends BaseResolutionPolicy
{
private final float mCameraWidth;
private final float mCameraHeight;
private float mMarginVertical; // Pixels from top of canvas to visible area, and from bottom of canvas to visible area
private float mMarginHorizontal; // Pixels from left of canvas to visible area, and from right of canvas to visible area
public CroppedResolutionPolicy(final float nCameraWidth, final float nCameraHeight)
{
this.mCameraWidth = nCameraWidth;
this.mCameraHeight = nCameraHeight;
this.mMarginVertical = 0;
this.mMarginHorizontal = 0;
}
// ===========================================================
// Getter & Setter
// ===========================================================
public float getMarginVertical()
{
return this.mMarginVertical;
}
public float getMarginHorizontal()
{
return this.mMarginHorizontal;
}
@Override
public void onMeasure(RenderSurfaceView pRenderSurfaceView, int pWidthMeasureSpec, int pHeightMeasureSpec)
{
BaseResolutionPolicy.throwOnNotMeasureSpecEXACTLY(pWidthMeasureSpec, pHeightMeasureSpec);
int measuredWidth = MeasureSpec.getSize(pWidthMeasureSpec);
int measuredHeight = MeasureSpec.getSize(pHeightMeasureSpec);
final float nCamRatio = (float)mCameraWidth / (float)mCameraHeight;
final float nCanvasRatio = (float)measuredWidth / (float)measuredHeight;
if( (float)measuredWidth / (float)measuredHeight < nCamRatio )
{
// Scale to fit height, width will crop
measuredWidth = (int) ( measuredHeight * nCamRatio);
this.mMarginHorizontal = ( this.mCameraWidth - ( (float) this.mCameraHeight * nCanvasRatio ) ) / 2.0f;
}
else
{
// Scale to fit width, height will crop
measuredHeight = (int) ( measuredWidth / nCamRatio );
this.mMarginVertical = ( this.mCameraHeight - ( (float) this.mCameraWidth / nCanvasRatio ) ) / 2.0f;
}
pRenderSurfaceView.setMeasuredDimensionProxy(measuredWidth, measuredHeight);
}
}
Use this class in engine creation in the following manner.
final CroppedResolutionPolicy canvasSurface = new CroppedResolutionPolicy( CAMERA_WIDTH, CAMERA_HEIGHT );
final EngineOptions engineOptions = new EngineOptions( true, ScreenOrientation.LANDSCAPE_FIXED, canvasSurface, new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT) );