简体   繁体   中英

How to make Wallpaper permanently fit to screen and in center?

I am trying to make the wallpaper fit to screen. I tried many solutions on this site but none worked for me except this one, but the image doesn't cover the screen. It kind of shrinks and it can appear anywhere on the screen, mostly in the center. The image size changes again on next reboot. Eg it appears in the middle and is much smaller than the screen size but when I reboot my device, the image size exceeds the bounds of the screen

  • How can I make it fit to the screen?
  • If I can't, how can I make it appear in the center permanently?
  • Does it depend on the dimensions (width, height) of the image too?

Below is my code:

Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
        imageIDs[imageIDforWallPaper]);
int w = bitmap.getWidth();
int h = bitmap.getHeight();
WallpaperManager wm = (WallpaperManager) getSystemService(WALLPAPER_SERVICE);
try {
    wm.setBitmap(bitmap);
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
wm.suggestDesiredDimensions(w, h);

What you are looking for is similar to a splash screen.

  1. The image shrinks because it has fixed width and height, and most probably they don't match with your device's dimensions. Every image will have a different width/height ratio, it isn't therefore a good idea trying to perfectly fit an image to one particular screen, as you may be able to do so (by modifying the image dimensions), but then you wouldn't be able to obtain the same result on every device: Devices and Displays
  2. Create a 9-patch image which adapts to every screen: 9-patch image introduction
  3. Yes it depends on width and height, but these values vary according to screen size and density. When you design an image you need to use dip (density-independent pixels) and create one image for each category of screen densities: Design for multiple screens

read also here: Android splash screen image sizes to fit all devices

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM