您的位置:首页 > 移动开发 > Android开发

android launcher壁纸滚动图片拉伸问题

2018-03-27 15:26 232 查看
修改源码如下,这个问题主要原因是没有根据图片实际尺寸设置壁纸大小
public static Point getDefaultWallpaperSize(Resources res, WindowManager windowManager,Activity activity) {
if (sDefaultWallpaperSize == null) {
Point realSize = new Point();
windowManager.getDefaultDisplay().getRealSize(realSize);
int maxDim = Math.max(realSize.x, realSize.y);
int minDim = Math.min(realSize.x, realSize.y);

// We need to ensure that there is enough extra space in the wallpaper
// for the intended parallax effects
final int defaultWidth, defaultHeight;
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;
}
sDefaultWallpaperSize = new Point(defaultWidth, defaultHeight);
}
return sDefaultWallpaperSize;
}
修改后的代码如下,主要是因为宽度不够导致,增加一个图片宽度int outWidth
public static Point getDefaultWallpaperSize(Resources res, WindowManager windowManager,Activity activity,int outWidth) {
//if (sDefaultWallpaperSize == null) {//注释这个代码
Point realSize = new Point();
windowManager.getDefaultDisplay().getRealSize(realSize);
int maxDim = Math.max(realSize.x, realSize.y);
int minDim = Math.min(realSize.x, realSize.y);

// We need to ensure that there is enough extra space in the wallpaper
// for the intended parallax effects
final int defaultWidth, defaultHeight;
if (res.getConfiguration().smallestScreenWidthDp >= 720) {
defaultWidth = (int) (maxDim * wallpaperTravelToScreenWidthRatio(maxDim, minDim));
defaultHeight = maxDim;
} else {
//defaultWidth = Math.max((int) (minDim * WALLPAPER_SCREENS_SPAN), maxDim);//此处就是屏幕壁纸宽度,这个宽度是写死的,所以图片会被放大拉伸
if(outWidth < minDim){                
defaultWidth = minDim;
}else{
defaultWidth = outWidth;
}
defaultHeight = maxDim;
}
sDefaultWallpaperSize = new Point(defaultWidth, defaultHeight);
//}//注释这个代码
return sDefaultWallpaperSize; }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐