在主屏幕上设置可滚动的壁纸

时间:2015-02-01 23:59:04

标签: android wallpaper android-screen-support android-wallpaper

我想在主屏幕上设置可滚动壁纸,但我的壁纸自动获得中心裁剪。 我正在使用的图像是比例" 3:2/16:9"所以我希望它们能够在主屏幕的多页上统一传播。

我目前正在使用:

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

wallpaperManager.setBitmap(wallPaperBitmap);

`

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

1 个答案:

答案 0 :(得分:-2)

从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));