1

我正在尝试制作一个更改系统壁纸的应用程序。在我的代码中,我得到了一个具有所需最小尺寸的图像(来自 WallpaperManager)。例如,在 Nexus One 上,所需的最小尺寸为 884x800。当我得到我的图像并将其设置为壁纸时,它会自动“左对齐”它,以便我只能看到 884x800 图像的左侧(Nexus One 的屏幕分辨率为 480x800)。

有没有办法可以将壁纸设置为“居中”?

我正在设置这样的壁纸:

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

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

注意:如果我得到 480x800 的图像,它会炸毁它,所以当它是壁纸时我只能看到左上角。

以下是 884x800 图像的示例:

这是我将其设置为墙纸时的外观示例:

以下是我使用 480x800 图像时的外观示例:

4

2 回答 2

0

您是否尝试过在虚拟主屏幕之间切换?你不是在最左边的虚拟主屏幕吗?

于 2013-08-29T00:11:42.353 回答
0

我的解决方案

最后,我得到了屏幕尺寸的图像(Nexus One 为 480x800),然后将其复制到所需尺寸的位图中(Nexus One 为 884x800)。

//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());
}

它适用于所有虚拟屏幕

于 2013-08-29T00:23:28.583 回答