开发者

Can I programmatically set a wallpaper to not scroll?

开发者 https://www.devze.com 2023-01-18 21:38 出处:网络
I am wri开发者_Go百科ting an app that allows a user to set the phone\'s wallpaper from a list of pictures.

I am wri开发者_Go百科ting an app that allows a user to set the phone's wallpaper from a list of pictures. By default it scrolls across the multiple home screens. I want the wallpaper on the home screen to be a static non-scrolling image.

What can I do programmatically to achieve this? Is this even possible?

I am using wallpaperManager.setResource(...); to set the wallpaper.

I've also tried wallpaperManager.setWallpaperOffsetSteps(0,0); but that did not solve my problem.


I'v fulfilled this feature by:

final WallpaperManager wpm = (WallpaperManager)getSystemService(
                Context.WALLPAPER_SERVICE);    
wpm.setWallpaperOffsetSteps(1, 1);
wpm.suggestDesiredDimensions(SCREEN_WIDTH, SCREEN_HEIGHT);


This is controlled by the Launcher application. If you want a non-scrolling wallpaper, install a Launcher app that doesn't scroll the wallpaper :)


Normally ImageWallpaper's size is set double wider than display's width so when you scroll home left or right, ImageWallpaper handles offsetchange events.

I've not tried this, but it may work i think. You may try this: [suggestDesiredDimensions]: http://developer.android.com/reference/android/app/WallpaperManager.html#suggestDesiredDimensions(int, int)

Set dimensions same as your workspace's width.


In case you do not know the screen width and screen height while setting wallpaper, this might help (P.S It is in Kotlin)

 val manager = WallpaperManager.getInstance(context)
 val drawable = manager.builtInDrawable
 manager.setWallpaperOffsetSteps(1F, 1F)
 val height = drawable.intrinsicHeight
 val width = drawable.intrinsicWidth
 val scaledBitmap = Bitmap.createScaledBitmap(bitmap, width, height,true)


If you want to put some effort into a solution, you could create a live wallpaper which displays a static, user-selectable image. Then your wallpaper could override the offset changes if that's what is desired. That's a lot of work, though, to stop the scrolling effect.

Alternatively, you could crop the image to the screen's size before setting it to wallpaper. That would stop the scrolling, but would break screen orientation changes.


can you try

final WallpaperManager wpm = (WallpaperManager)getSystemService(
                Context.WALLPAPER_SERVICE);    
wpm.setWallpaperOffsetSteps(1, 1);
wpm.suggestDesiredDimensions(SCREEN_WIDTH, SCREEN_HEIGHT);


For extremally decrease scrolling just crop a bitmap to device screen ratio, for example 9*16 and set this bitmap by wallpaper manager, but it works for one screen orientation (it is OK for smart phones). Other solutions do not work.

0

精彩评论

暂无评论...
验证码 换一张
取 消