我正在尝试设置我的动态壁纸的背景,以便完美地适合屏幕。当前壁纸尺寸为1024x1024,但只有部分图像出现在我的HTC Desire屏幕上(尺寸为480 x 800)。 此外,当我尝试设置小于480x800的图像时,图像不会拉伸以适合整个屏幕。
有什么方法可以实现这一点,以便无论屏幕大小如何,壁纸都能完美地适应高度?
以下是我的代码供您参考 -
private static final int CAMERA_WIDTH = 480;
private static final int CAMERA_HEIGHT = 720;
@Override
public EngineOptions onCreateEngineOptions() {
final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
return new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
}
@Override
public void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback) throws Exception {
.
.
this.mBitmapBackgroundAtlas1 = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024);
this.mFaceBackgroundRegion1 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapBackgroundAtlas1, this, "bg1.jpg", 0, 0);
this.mBitmapBackgroundAtlas1.load();
.
.
}
@Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws Exception {
this.mEngine.registerUpdateHandler(new FPSLogger());
.
.
mScene.setBackground(new SpriteBackground(new Sprite(0, 0, mFaceBackgroundRegion1, this.getVertexBufferObjectManager())));
.
.
}
答案 0 :(得分:3)
您可以覆盖具有width和height作为参数的onSurfaceChanged方法。这将给出设备的屏幕宽度/高度。
您可以使用此值将图像缩放到您的要求。
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
this.screenWidth=width;
this.screenHeight=height;
}