我创建了一个动态壁纸它在纵向模式下工作正常,但是当我将手机置于横向模式时,视图显示不正确。现在我要做的是“在纵向模式下修复屏幕方向”。我怎么能为动态壁纸做这个? 我试图旋转位图和画布,但看起来不太好。是否有关于旋转画布和位图的教程?请建议,请告诉我我的问题。 提前谢谢。
答案 0 :(得分:1)
请查看我的代码:
public class PonyWallpaper extends AnimationWallpaper {
/*some code here*/
class PonyEngine extends AnimationEngine {
/*some code here as well*/
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format,
int width, int height) {
Log.v("orientation changed", "w: "+width + " h: " + height + " width desired: " + this.getDesiredMinimumWidth() + " height desired: " + this.getDesiredMinimumHeight());
将AnimationEngine声明为
protected abstract class AnimationEngine extends android.service.wallpaper.WallpaperService.Engine
从横向切换到肖像时的输出:
方向改变(352):w:800小时:480宽度:960高度 期望:800
从肖像切换到横向时的输出:
方向改变(352):w:480小时:800宽度:960高度 期望:800
如您所见,每次更改方向时,都会调用android.service.wallpaper.WallpaperService.Engine类的onSurfaceChanged方法。
从我注意到的,
this.getDesiredMinimumWidth()
和
this.getDesiredMinimumHeight()
不要更改并且是宽度和高度的最大可能值。
我的解决方案是:
onOffsetsChanged
的方法
android.service.wallpaper.WallpaperService.Engine
我希望这会有所帮助!