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

修改源码如下,这个问题主要原因是没有根据图片实际尺寸设置壁纸大小
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; }

猜你喜欢

转载自blog.csdn.net/zhuxingchong/article/details/79713598
今日推荐