2012-05-08 27 views
1

我想設置我的動態壁紙的背景以便完美地適合屏幕。當前壁紙尺寸是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()))); 
. 
. 
} 

回答

3

行代碼......找到了答案。發佈給那些也在尋找相同的人。

您可以重寫方法onSurfaceChanged,它具有寬度和高度作爲參數。這給出了設備的屏幕寬度/高度。

您可以使用此值將圖像縮放到您的要求。

@Override 
public void onSurfaceChanged(GL10 gl, int width, int height) { 
this.screenWidth=width; 
this.screenHeight=height; 
}