Prevent Live Wallpaper from changing screen orient

2019-06-24 03:51发布

问题:

I'm working on a Live Wallpaper and I would like to keep it always in portrait mode. I know it's possible for an Activity to declare the orientation in the Manifest, but I can't find a way to do the same with a live wallpaper service. Is it possible somehow to tell the Wallpaper Engine to swap the x and y axis in the rendering process or something similar, because I have no idea anymore.

回答1:

Use the following method to check for orientation changes

public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height)

If width is greater than height you know that the orientation changed to landscape.

Be sure that you now treat x as y and y as x. Same goes for width and height.



回答2:

You have handle the orientation change for live wallpaper. you can't fix the orientation.