中心的Android壁纸 [英] Center Android Wallpaper
问题描述
我想做出改变系统壁纸的应用程序。在我的code我得到一个具有所需的最小尺寸(从WallpaperManager)的图像。例如在Nexus One上所需的最小尺寸是884x800。当我得到我的形象andset它作为墙纸,它会自动对齐左它让我可以看到只有884x800的图像的左侧(Nexus One手机的屏幕解析度是480×800)。
I'm trying to make an app that changes the system wallpaper. In my code I get an image that has the desired minimum dimensions (from WallpaperManager). For example on the Nexus One the desired minimum dimensions are 884x800. When I get my image andset it as the wallpaper it automatically "left aligns" it so that I can see only the left side of the 884x800 image (The Nexus One's screen res is 480x800).
有没有办法,我可以设置壁纸故有中心?
Is there a way I can set the wallpaper so it is "centered"?
我设置的墙纸是这样的:
I am setting the wallpaper like this:
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext());
try {
wallpaperManager.setBitmap(bitmap);
} catch (IOException e) {
Log.e("Error", e.toString());
}
注意:如果我得到为480x800的它吹起来,所以我只能看到当它是壁纸的左上角的图片
NOTE: If I get the image as 480x800 it blows it up so I can only see the top left corner when it is the wallpaper.
下面是一个形象,是884x800的例子:
Here is an example of an image that is 884x800:
下面是什么样子时,我将其设置为墙纸的例子:
Here is an example of what it looks like when I set it as the wallpaper:
下面是什么样子时,我用一个480x800的图像的例子:
Here is an example of what it looks like when I use a 480x800 image:
推荐答案
我的解决方案
在结束我在屏幕尺寸的图像(480×800的Nexus One的),然后复制成一个位图,它是需要的尺寸(884x800对Nexus One的)。
In the end I got the image in the screen size (480x800 for the Nexus One) and then copied it into a bitmap that was the desired dimensions (884x800 for the Nexus One).
//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());
}
和它适用于所有的虚拟屏幕
And it works on all virtual screens
这篇关于中心的Android壁纸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!