[DESCRIPTION]
系统WallPaper图片可以设置成屏幕大小的图吗?
[SOLUTION]
系统默认的Wallpaper图片都是两倍屏宽,主要有2个目的:
1. 壁纸可以随着Launcher Workspace的滑动而滑动;
2. 屏幕横屏时,设置了show wallpaper flag的应用背景可以正常显示。
如果将Wallpaper宽高修改为与屏幕宽高相同,就会造成如下隐患:
1. Launcher Workspace的背景会被拉伸,表现不美观;
2. 设置了show wallpaper flag的应用背景在横屏时显示不全(右边会显示黑屏,例如recent界面)。
隐患1可以通过修改代码解决(下面的代码就是为了解决隐患1),隐患2也是存在的。因此不建议这样修改。
N/M:
1. 请在WallpaperUtils.java的getDefaultWallpaperSize方法中,请找到如下代码:
if (res.getConfiguration().smallestScreenWidthDp >= 720) {
defaultWidth = (int) (maxDim * wallpaperTravelToScreenWidthRatio(maxDim, minDim));
defaultHeight = maxDim;
} else {
defaultWidth = Math.max((int) (minDim * WALLPAPER_SCREENS_SPAN), maxDim);
defaultHeight = maxDim;
}
if (res.getConfiguration().smallestScreenWidthDp >= 720) {
defaultWidth = (int) (maxDim * wallpaperTravelToScreenWidthRatio(maxDim, minDim));
defaultHeight = maxDim;
} else {
defaultWidth = Math.max((int) (minDim * WALLPAPER_SCREENS_SPAN), maxDim);
defaultHeight = maxDim;
}
请先确认代码走哪个分支(这与手机分辨率有关),然后把defaultWidth 和defaultHeight 改为屏幕宽高。修改方法如下(以else分支示例):
Point realSize = new Point();
windowManager.getDefaultDisplay().getRealSize(realSize);
windowManager.getDefaultDisplay().getRealSize(realSize);
if (isScreenLarge(res)) {
defaultWidth = (int) (maxDim * wallpaperTravelToScreenWidthRatio(maxDim, minDim));
defaultHeight = maxDim;
} else {
defaultWidth = realSize.x;
defaultHeight = realSize.y;
}
defaultWidth = (int) (maxDim * wallpaperTravelToScreenWidthRatio(maxDim, minDim));
defaultHeight = maxDim;
} else {
defaultWidth = realSize.x;
defaultHeight = realSize.y;
}
KK/L:
1. 请在WallpaperCropActivity.java的getDefaultWallpaperSize方法中,请找到如下代码:
if (isScreenLarge(res)) {
defaultWidth = (int) (maxDim * wallpaperTravelToScreenWidthRatio(maxDim, minDim));
defaultHeight = maxDim;
} else {
defaultWidth = Math.max((int) (minDim * WALLPAPER_SCREENS_SPAN), maxDim);
defaultHeight = maxDim;
}
请先确认代码走哪个分支(这与手机分辨率有关),然后把defaultWidth 和defaultHeight 改为屏幕宽高。修改方法如下(以else分支示例):
1. 请在WallpaperCropActivity.java的getDefaultWallpaperSize方法中,请找到如下代码:
if (isScreenLarge(res)) {
defaultWidth = (int) (maxDim * wallpaperTravelToScreenWidthRatio(maxDim, minDim));
defaultHeight = maxDim;
} else {
defaultWidth = Math.max((int) (minDim * WALLPAPER_SCREENS_SPAN), maxDim);
defaultHeight = maxDim;
}
请先确认代码走哪个分支(这与手机分辨率有关),然后把defaultWidth 和defaultHeight 改为屏幕宽高。修改方法如下(以else分支示例):
Point realSize = new Point();
windowManager.getDefaultDisplay().getRealSize(realSize);
windowManager.getDefaultDisplay().getRealSize(realSize);
if (isScreenLarge(res)) {
defaultWidth = (int) (maxDim * wallpaperTravelToScreenWidthRatio(maxDim, minDim));
defaultHeight = maxDim;
} else {
defaultWidth = realSize.x;
defaultHeight = realSize.y;
}
defaultWidth = (int) (maxDim * wallpaperTravelToScreenWidthRatio(maxDim, minDim));
defaultHeight = maxDim;
} else {
defaultWidth = realSize.x;
defaultHeight = realSize.y;
}
2.
请找到WallpaperManagerService.java的loadSettingLocked方法,去掉如下代码:
if (wallpaper.width < baseSize) {
wallpaper.width = baseSize;
}
if (wallpaper.width < baseSize) {
wallpaper.width = baseSize;
}