Android Live Wallpaper -- Force Portrait
This question has been asked before, but with 开发者_开发问答no answer.
Is it possible to force a live wallpaper to display in portrait mode at all times, ignoring orientation changes? As there is no activity, I cannot do this the normal way.
Thanks!
Yes, it is possible but it's tricky. You can't avoid orientation changes in your code for you'll have to rotate your wallpaper in order to always have it in portrait mode.
Have width and height monitored in
public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height)
method of a
android.service.wallpaper.WallpaperService.Engine
class. It gets called every time the orientation changes. If width is greater than height then you'll most probably in landscape mode.
Then just treat x as y and width as height and rotate any bitmaps you have. This should work.
精彩评论