wallpaper 图片小不能铺满桌面

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qwertyuiop159158/article/details/48161107

当用户自定义壁纸的时候,如果采用了分辨率比较小的图片,就会导致铺不满屏幕,会留下黑影

解决思路:

根据平板的分辨率进行适应,如果图片的分辨率符合显示的分辨率则不做处理,否则 将图片进行相应的拉伸

关键点文件:/data/system/wallpaper_info.xml

每次更换壁纸,所对应的分辨率就会写在该文件之中

--- a/android/frameworks/base/services/java/com/android/server/WallpaperManagerService.java
+++ b/android/frameworks/base/services/java/com/android/server/WallpaperManagerService.java
@@ -663,8 +663,16 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
             height = Math.max(height, displaySize.y);
 
             if (width != wallpaper.width || height != wallpaper.height) {
-                wallpaper.width = width;
-                wallpaper.height = height;
+        //        wallpaper.width = width;
+             //   wallpaper.height = height;
+             if(width < 1424 || height < 1280){
+   wallpaper.width = 1424;
+    wallpaper.height = 1280;
+    }else{
+     wallpaper.width = width;
+     wallpaper.height = height;
+
+    }
                 saveSettingsLocked(wallpaper);
                 if (mCurrentUserId != userId) return; // Don't change the properties now
                 if (wallpaper.connection != null) {
@@ -1160,11 +1168,16 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
 
         // We always want to have some reasonable width hint.
         int baseSize = getMaximumSizeDimension();
+  
+        if (DEBUG) Slog.v(TAG, "baseSize===   "+baseSize+"    wallpaper.width=  "+ wallpaper.width+"   wallpaper.height==  "+wallpaper.height);
         if (wallpaper.width < baseSize) {
-            wallpaper.width = baseSize;
+            //wallpaper.width = baseSize;
+            wallpaper.width =1424;          
         }
         if (wallpaper.height < baseSize) {
-            wallpaper.height = baseSize;
+     //       wallpaper.height = baseSize*2;
+    
+      wallpaper.height = 1280;
         }
     }
 
diff --git a/android/packages/apps/Launcher3/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java b/android/packages/apps/Launcher3/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
index 561c4bb..14d2e41 100644
--- a/android/packages/apps/Launcher3/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
+++ b/android/packages/apps/Launcher3/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
@@ -812,10 +812,14 @@ public class WallpaperCropActivity extends Activity {
         int savedHeight = sharedPrefs.getInt(WALLPAPER_HEIGHT_KEY, defaultWallpaperSize.y);
         if (savedWidth != wallpaperManager.getDesiredMinimumWidth() ||
                 savedHeight != wallpaperManager.getDesiredMinimumHeight()) {
+   if(savedWidth < 1424 || savedHeight <1280){
+
+            wallpaperManager.suggestDesiredDimensions(1424, 1280);
+}else{
             wallpaperManager.suggestDesiredDimensions(savedWidth, savedHeight);
         }
     }
-
+}
     protected static RectF getMaxCropRect(
             int inWidth, int inHeight, int outWidth, int outHeight, boolean leftAligned) {
         RectF cropRect = new RectF();

猜你喜欢

转载自blog.csdn.net/qwertyuiop159158/article/details/48161107