Search code examples
androidwallpaperandroid-screen-supportandroid-wallpaper

set scrollable wallpaper across homescreen


I want to set scrollable wallpaper on homescreen but my wallpaper gets center crop automatically. The images i am using are in ratio "3:2/ 16:9" so i want them to get spread uniformly on multiple pages of homescreen.

I am currently using:

wallpaperManager.suggestDesiredDimensions(width, height);
wallPaperBitmap = BitmapFactory.
                        decodeStream(url);

wallpaperManager.setBitmap(wallPaperBitmap);

`

<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="21"/>

Solution

  • Got the help from androidhive.com

    //get screen height
    Display display = getWindowManager().getDefaultDisplay();
            Point size = new Point();
            display.getSize(size);
            screenHeight = size.y;
    
    
     wallPaperBitmap= ... //your bitmap resource
    
    //adjust the aspect ratio of the Image
    //this is the main part
    int width = wallPaperBitmap.getWidth();
                width = (width * screenHeight) / wallPaperBitmap.getHeight();
    //set the wallpaper
    //this may not be the most efficent way but it works
    wallpaperManager.setBitmap(Bitmap.createScaledBitmap(wallPaperBitmap, width, height, true));