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; }
相关文章推荐
- 解决android:background背景图片被拉伸问题
- android ListView常见问题解决方法(滚动背景变黑,去除滑动时阴影,拖动时Item图片不显示)
- Android自定义控件系列八:详解onMeasure()(二)--利用onMeasure测量来实现图片拉伸永不变形,解决屏幕适配问题
- Android自定义控件系列八:详解onMeasure()(二)--利用onMeasure测量来实现图片拉伸永不变形,解决屏幕适配问题
- android 解决按钮、imageView 背景图片拉伸变大的问题
- Android Launcher3壁纸居中问题
- 解决android:background背景图片被拉伸问题
- 解决android:background背景图片被拉伸问题
- 解决android:background背景图片被拉伸问题
- 解决android:background背景图片被拉伸问题
- android listview 异步加载图片并防止错位及解决ListView滚动后内容重复的问题
- android listview 滚动时异步加载图片的问题
- Android自定义控件系列八:详解onMeasure()(二)--利用onMeasure测量来实现图片拉伸永不变形,解决屏幕适配问题
- android ListView多线程解决图片错位问题、缩略图问题、实现顺滑滚动
- Android自定义控件系列八:详解onMeasure()(二)--利用onMeasure测量来实现图片拉伸永不变形,解决屏幕适配问题
- 解决android:background背景图片被拉伸问题
- 解决android:background背景图片被拉伸问题
- android:background="@drawable/"图片拉伸问题
- 解决android:background背景图片被拉伸问题
- Android自定义控件系列八:详解onMeasure()(二)--利用onMeasure测量来实现图片拉伸永不变形,解决屏幕适配问题