2013-08-28 151 views
1

我正在嘗試改變系統壁紙的應用程序。在我的代碼中,我得到了一個具有所需最小尺寸的圖像(來自WallpaperManager)。例如在Nexus One上,所需的最小尺寸爲884x800。當我得到我的圖像,並將其設置爲牆紙時,它會自動「左對齊」,以便我只能看到884x800圖像的左側(Nexus One的屏幕分辨率爲480x800)。中心Android壁紙

有沒有一種方法可以將壁紙設置爲「居中」?

我設置的牆紙是這樣的:

WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext()); 

try { 
    wallpaperManager.setBitmap(bitmap); 
} catch (IOException e) { 
    Log.e("Error", e.toString()); 
} 

注:如果我爲480x800的它吹起來的形象,所以我只能看到左上角當它是牆紙。

這裏是一個形象,是884x800的例子:

這裏是什麼樣子時,我將其設置爲壁紙爲例:

下面是我使用480x800圖像時的外觀示例:

回答

0

您是否嘗試在虛擬主屏幕之間切換?你不是在最左邊的虛擬主屏幕嗎?

0

我的解決辦法

在我的屏幕尺寸(480×800的Nexus之一)中的圖像,然後複製它變成一個位圖,這是所希望的尺寸(884x800的Nexus之一)的端部。

//Getting the image 
Display display = getWindowManager().getDefaultDisplay(); 
     screenSize = new Point(); 
display.getSize(screenSize); 
new LoadImageTask(screenSize.x, screenSize.y, this).execute(); 

...

// In the response listener 
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this); 
Point desiredSize = new Point(
     wallpaperManager.getDesiredMinimumWidth(), 
     wallpaperManager.getDesiredMinimumHeight()); 

Bitmap wallpaper = Bitmap.createBitmap(desiredSize.x, desiredSize.y, Bitmap.Config.ARGB_8888); 
Canvas canvas = new Canvas(wallpaper); 
canvas.drawBitmap(bitmap, 0, 0, null); 

try { 
    wallpaperManager.setBitmap(wallpaper); 
} catch (IOException e) { 
    Log.e("Error", e.toString()); 
} 

它適用於所有的虛擬屏幕